2016-04-14 123 views
0

我有一個「用戶」表和一個「cDetails」表。在cDetails表裏我有一個名爲「full_name」的字段。我試圖根據當前登錄的用戶檢索並輸出此表中的值。快速解析數據

在cDetails表中,我有一個名爲「createdBy」的字段,該字段指向創建它的Users表中的objectID 。

這是我到目前爲止有:

let query = PFQuery(className: "cDetails") 

    let currentUser = PFUser.currentUser() 
    query.includeKey("full_name") 
    query.whereKey("createdBy", equalTo: currentUser!.objectId!) 
    print("CREATED BY " + PFUser.currentUser()!.objectId!); 
    query.findObjectsInBackgroundWithBlock { 
     (objects, error) -> Void in 
     if objects == nil { 
      print(objects) 
      print("called") 
      // self.full_nameLabel.text = "\(query)" 
     } else { 
      print("FAILED") 
     } 
    } 
+0

什麼錯誤(S)你得到繼續嗎? –

回答

0

我的方法:

let query = PFQuery(className: "cDetails") 

let currentUser = PFUser.currentUser() 
query.includeKey("full_name") 
query.whereKey("createdBy", equalTo: currentUser!.objectId!) 
print("CREATED BY " + PFUser.currentUser()!.objectId!); 
query.findObjectsInBackgroundWithBlock { 
    (objects, error) -> Void in 
    if **objects == nil** { 
     print(objects) 
     print("called") 
     // self.full_nameLabel.text = "\(query)" 
    } else { 
     print("FAILED") 
    } 

}

您正在尋找是否objects == nil。你想擁有你的error == nil和你objects != nil

之後,隨着

for object in objects { 

let fullName = object["full_name"] as! String 

}