在尝试在Parse中设置指向另一个类对象的指针时,我一直遇到错误。从objectID设置指针的正确格式是什么?
错误:
[Error]: invalid type for key RestaurantName, expected *Restaurant, but got string (Code: 111, Version: 1.6.1)
代码:
var uploadPhoto = PFObject(className:"FoodPhoto")
uploadPhoto.setObject("lZJJHkFmQl", forKey: "RestaurantName")
uploadPhoto["PhotoName"] = "title"
let imageFile = PFFile(name:"image.png", data:imageData)
uploadPhoto["PhotoUploaded"] = imageFile
uploadPhoto["Votes"] = 0
uploadPhoto.saveInBackgroundWithBlock {
(success: Bool, error: NSError!) -> Void in
if (success) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
答案 0 :(得分:0)
您有一个对象id字符串,而指针是对实际对象的引用。该对象id表示对象,或者更确切地说是唯一标识对象,但是您无法通过它来创建指针。您需要获取与id关联的对象。
如果您已经拥有它,那么请将它替换为您当前放置字符串的位置。
如果您不这样做,则需要通过运行查询来获取它。从技术上讲,您可以在不同的字段中传递字符串对象ID,并进行云代码查询并设置指针(如果您还没有该对象,这将比从设备查询更有效。)
答案 1 :(得分:0)
您可以使用
创建指针PFObject(withoutDataWithClassName: "your_class_name", objectId: "your_object_id")
功能,并将其设置为字段。