Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在解析iOS中更新对象_Ios_Swift_Parse Platform - Fatal编程技术网

在解析iOS中更新对象

在解析iOS中更新对象,ios,swift,parse-platform,Ios,Swift,Parse Platform,我在将解析文档转换为新的Swift需求时遇到困难。我想更新一个对象,但我一直收到一个错误,无法将类型为Bool的值分配给类型AnyObject?我知道“查看”栏是Bool。这是我的密码 var query = PFQuery(className:"Post") query.getObjectInBackgroundWithId(self.threadImageIds[objectIDkey]) { (object, error) -> Void in if error != nil

我在将解析文档转换为新的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()
  }
}

提前感谢。

您不能在那里存储
BOOL
,您需要使用
BOOL的
NSNumber
。尝试按NSNumber的方式执行
true

在进行了大量搜索并尝试按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()
        }
    }

它不起作用,因为您试图将下标应用于可选对象,而不是对象,所以请尝试展开

object!["viewed"] = true

我不知道斯威夫特,但我认为这个错误清楚地表明对象必须被键入为PFObject?只是想一想,尝试将
(对象,错误)
更改为
(对象:PFObject!错误:NSError!)
@danh-这也不起作用,这很奇怪,因为正如Portland Runner引用的那样,过去,您必须输入'object:PFObject',现在这甚至是不允许的。@PortlandRunner-这显示了它自己的错误。在新的Swift问世后,我不得不重新检查代码,把所有的代码都取出来。谢谢你的邀请look@FabianBoulegue我试着按照你在这篇文章中回答的方式展开,我得到了与那篇文章中提到的相同的错误。想知道你有什么想法吗?我试过了,但也没用。它说你不能给任何对象分配类型NSNumber?这真的很奇怪。尝试
NSNumber(bool:true)