【问题标题】:Swift 2 error handling - callback and image saving with ParseSwift 2 错误处理 - 使用 Parse 进行回调和图像保存
【发布时间】:2015-10-29 21:32:47
【问题描述】:

我试过转换工具更新这几行代码,可惜进程没有赶上这两个错误。

您能否帮助我了解是否需要引入 do { 和错误处理? (我是 swift 新手!)。

我收到的错误信息如下:“Call can throw, but it is not mark with 'try' and the error is not processed”

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

query.findObjectsInBackgroundWithBlock {(result: [PFObject]?, error: NSError?) -> Void in

self.posts = result as? [Post] ?? []

  // 1
  for post in self.posts {
  // 2
    let data = post.imageFile?.getData()  --> this is where I get the error message
  // 3
    post.image = UIImage(data: data!, scale:1.0)
  }

  self.tableview.reloadData()
}

【问题讨论】:

    标签: parse-platform error-handling swift2


    【解决方案1】:

    安装:let data = post.imageFile?.getData()

    改用这个:

    do
    {
        try let data = post.imageFile?.getData()
    }
    catch
    {
        print("Error: \(error)")
        //Handle the error instead of print probably
    }
    

    【讨论】:

    • 非常感谢您的回答。它在 'data' 上创建了一个新问题:for post in self.posts { do { let data = try post.imageFile?.getData() } catch { print("Error: (error)") //处理错误而不是打印可能 } post.image = UIImage(data: data!, scale:1.0) --> 使用未解析的已识别“数据”或者我们刚刚用 let.. 定义了它.. } self.tableview.reloadData() } }
    猜你喜欢
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 2015-09-06
    相关资源
    最近更新 更多