ios - 在 Parse iOS 中更新对象

标签 ios swift parse-platform

我在将 Parse 文档转换为新的 Swift 要求时遇到了问题。我想更新一个对象,但我总是收到一个错误,我无法将类型 Bool 的值分配给类型 AnyObject?我知道“已查看”列是 Bool。这是我的代码。

var query = PFQuery(className:"Post")
query.getObjectInBackgroundWithId(self.threadImageIds[objectIDkey]) {
  (object, error) -> Void in
  if error != nil {
      println(error)
  } else {
      object["viewed"] = true // this is where error is occuring
      object!.saveInBackground()
  }
}

提前致谢。

最佳答案

经过大量搜索并尝试按照 Swift 希望我的方式解包可选值后,下面的方法起作用了

    query.getObjectInBackgroundWithId(self.threadImageIds[objectIDkey]) {
        (object, error) -> Void in
        if error != nil {
            println(error)
        } else {
            if let object = object {
                object["viewed"] = true as Bool
            }
            object!.saveInBackground()
        }
    }

关于ios - 在 Parse iOS 中更新对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29618660/

相关文章:

ios - UIRefreshControl 未按正确顺序加载

objective-c - 防止 UIImage 在 -drawInRect : is called 时调整大小

ios - 调用中的 NSDictionary 额外参数 "forKey"

swift - 在 Swift 3 和 Xcode 中使用堆栈 View 按钮打开 Storyboard View

javascript - 使用 for 循环通过 Parse 创建子类对象

ios - 查询后写入 Parse 列 - Swift

javascript - 如何使用javascript将图像保存在解析云中

ios - 在 TableView 中按下自定义按钮后重新加载整个 ViewController

ios - Sendbird 不在 iOS 上推送通知

ios - 将 image/jpeg 从 GET 请求转换为 UIImage