我有两个类 Place 和 BeenHere。 BeenHere 具有名为“toPlace”和“fromUser”的指针,相应地指向 Class Place 和 User。 Place 依次具有我想要检索并显示在 ViewController 中的标题和图像 (PFFile)。在下面的代码中,我已经到达了带有 objectId 的指针,但不知道现在如何检索与该指针指向的特定位置相关的标题和图像。感谢您的帮助和建议。
class UserBeenHereViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let user = PFUser.currentUser()?.username
if user != nil {
let query = PFQuery(className: "BeenHere")
query.includeKey("toPlace")
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if error == nil {
for object in objects! {
print(object["toPlace"].objectId)
}
}
else {
print("There is error")
}
}
}
}
最佳答案
首先,您需要将“toPlace”放入一个 PFObject 中,然后访问它。所以在你的情况下它应该看起来像:
var toPlace = comment["toPlace"] as? PFObject
print (toPlace["title"])
关于swift - 使用指针解析检索 PFObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38676925/