我试图访问" objectId"字段"用户"表,同时在"照片"上运行查询表
这是在"照片"上运行的Parse.com查询(简化)。表:
func checkDbForNewPhotos() {
var query = PFQuery(className:"Photos")
query.whereKey("fbId", equalTo:"34343434343434")
query.includeKey("user.objectId"); // Is this what is needed to access user info ?
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
for object in objects {
println(object) // See sample object below
println(user.objectId) // Error here: user type doesn't have member objectId
}
println(object):这是从查询返回的示例对象。我试图从"用户"访问9wEGRWSnTk field是指向另一个表的指针。
<Photos: 0x7c091fd0, objectId: 6D0aHreHsC, localId: (null)> {
alerts = 0;
country1 = france;
country2 = "";
imageFile = "<PFFile: 0x7b7d9130>";
user = "<PFUser: 0x7b7d95f0, objectId: 9wEGRWSnTk>";
}
如何在swift中格式化以访问9wEGRWSnTk?
答案 0 :(得分:3)
我遇到了同样的问题。您需要将其转换为PFUser,然后访问该信息。
let pfObject:PFObject = object as PFObject
let userObject:PFUser = pfObject["user"] as PFUser
print("User \(userObject.objectId)")
答案 1 :(得分:1)
你应该使用
println(object["user"].objectId)
如果您存储用户的列名为“user”。
答案 2 :(得分:1)
您也可以说EqualTo并使用PFUser.currentuser() 这样你只从该用户加载所有内容 否则尝试解释为什么在查询时需要objectId
query.whereKey("user", equalTo: PFUser.currentUser())