我在将 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/