我目前正在尝试将当前用户添加到 Parse.com 数据库中的数组列表中。数据库有一列名为“Likers”的数组类型。当他们按下按钮时尝试将用户名附加到数组时,我收到以下错误。
Cannot invoke 'append' with an argument list of type '(String?)'
我的代码发布在下面。如果有人能给我一些关于如何解决这个问题的见解,那就太好了。我目前正在运行 xCode 6.3 和 Swift 1.2。
@IBAction func likedTapped(sender: AnyObject) {
var user = PFUser.currentUser()?.username
var likers = ["Likers"]
["Likers"].append(user) // <-- This is where I get the error above
}
最佳答案
在这一行中:
var likers = ["Likers"]
您正在声明一个名为 Likers 的字符串数组,其值为字符串“Likers”。
然后在这一行中:
["Likers"].append(user)
您应该像这样使用声明的 Likers 变量。
likers.append(user)
希望这能解释您如何错误地使用数组声明。但是,您也错误地处理了 Parse 数据存储,因为需要存储它们以使用 Parse 对象进行解析。
Some information on parse object creation can be found here.
这绝对值得一读,以帮助理解 Parse 的使用。
关于ios - 无法使用参数列表调用类型 'append',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34317591/