【问题标题】:func writeImageToFile(path: String, completeBlock: (success: Bool) -> Void){ }func writeImageToFile(path: String, completeBlock: (success: Bool) -> Void){ }
【发布时间】:2016-08-06 15:27:00
【问题描述】:

我正在尝试使用 DKimagepickercontroller 上传图像,这是一种将其上传到 url 的方法,但我混淆了我应该放入 completeBlock: (success: Bool) - Void 的内容

func writeImageToFile(path: String, completeBlock: (success: Bool) -> Void){

}

这是我在 xcode 中编写的代码 let apath = "http://localhost/swift/upload.php" writeImageToFile(apath,completeBlock: (success: false) -> Void) 但我得到了这个错误

expected expression in the list of expressions and this error expexted ',' separator

【问题讨论】:

    标签: swift xcode uiimagepickercontroller


    【解决方案1】:

    你必须这样称呼它writeImageToFile(path) { success in print(success) }

    【讨论】:

      【解决方案2】:

      这个块应该用作尾随闭包,不要把它留在签名中。

      在 Xcode 中看起来像这样:stackoverflow.com/a/33020097/2227743

      任务完成后使用闭包参数,在您的情况下,它将指示文件是否已写入。

      例如,您可以在闭包中测试success

      writeImageToFile(somePath) { (success) in
          if success {
              // the file has been written
          } else {
              // the file hasn't been written
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-10-31
        • 2022-11-12
        • 1970-01-01
        • 2013-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多