【问题标题】:Using Parse Array key with Swift "Error: type() does not conform to protocol AnyObject"在 Swift 中使用 Parse Array 键“错误:type() 不符合协议 AnyObject”
【发布时间】:2015-05-30 06:51:58
【问题描述】:

我正在尝试在我的解析数据库中创建一个 ObjectId 和 Int 数组。我的代码中有以下内容,但收到“错误:type() 不符合协议‘AnyObject’”。

   var bN:Array<String> = []

var bb:Array<Int> = []

@IBAction func myBtn (sender: AnyObject) {

   var userPost = PFObject(className:”UserPost")

    // Object ID of user's post

    userPost.objectId = dObjectId

    println(“User objectId is \(dObjectId)")

    let userOId:NSString = PFUser.currentUser().objectId

    println(userOId) // Gives the current user ObjectId

    let userB = myB.text.toInt()!

    println(userB)



    userPost[“myB"] = bN.append("\(userOId)") // Here is where I get the first error: type() does not conform to protocol AnyObject

    userPost[“myC"] = bb.append("\(userB)") // Here is where I get the second error: type() does not conform to protocol AnyObject



   userPost.saveInBackgroundWithBlock {
        (success: Bool, error: NSError!) -> Void in
        if (success) {

            // The object has been saved.
            println("Saved")

            self.displayAlert("Saved!", error: "")

        } else {
            // There was a problem, check error.description
            println("Error")

} }

提前致谢。

【问题讨论】:

  • 怎么了?
  • @tskulbru 复制粘贴造成了一些问题。抱歉,已编辑。现在你能帮忙消除错误吗?

标签: ios swift parse-platform


【解决方案1】:

您需要显式转换要检索的属性:

userPost[“myB"] = bN.append("\(userOId)”) as String

【讨论】:

  • 我试过“as String”和“as NSString”。我收到一个错误:“类型 '()' 不能转换为 'String/NSString'” 还有什么可能导致此错误?有没有其他方法可以在解析数据库中获取数组?我想要评论海报 ObjectId 和它的评论(在我的情况下,评论是 Int)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-23
相关资源
最近更新 更多