我在Swift中使用Parse框架。我有以下代码
var user = PFUser()
user.username = "username"
user.password = "password"
user.addObject("firstname", forKeyedSubscript: "firstName")
user.addObject("lastName", forKeyedSubscript: "lastName")
user.addObject("mobileNumber", forKeyedSubscript: "mobile")
user.addObject("city", forKeyedSubscript: "city")
user.signUpInBackgroundWithBlock { succeeded, error in
if (succeeded) {
//The registration was successful
} else if let error = error {
//Something bad has occurred
}
}
在门户网站中,它显示如下:
它使用我给出的键在列中创建'数组'。我希望他们成为字符串。所以,我已将代码更改为以下内容。所以,我已经将addObject更改为setObject,如下所示:
var user = PFUser()
user.username = "username"
user.password = "password"
user.setObject("firstname", forKeyedSubscript: "firstName")
user.setObject("lastName", forKeyedSubscript: "lastName")
user.setObject("mobileNumber", forKeyedSubscript: "mobile")
user.setObject("city", forKeyedSubscript: "city")
user.signUpInBackgroundWithBlock { succeeded, error in
if (succeeded) {
//The registration was successful
} else if let error = error {
//Something bad has occurred
}
}
显示以下错误
[Error]: invalid type for key city, expected array, but got string (Code: 111, Version: 1.8.3)
如何使用Swift代码在键中添加字符串?
答案 0 :(得分:0)
您需要在parse.com门户网站上将city
,firstName
,lastName
和mobile
的列类型更改为String
。您需要删除此列并添加具有相同名称和正确类型的新列。
答案 1 :(得分:0)
问题是您已经在此实体上创建了与您现在要设置的类型不同的列。
根据数据库中的数据量,我建议您删除这些列。您必须使用Parse仪表板执行此操作。