Variables 变量在Swift 2中包含零值
我在类的顶部声明了一个变量destinationID。第一次打印显示变量的正确内容,而第二次打印显示的是nil值 有人知道问题出在哪里吗Variables 变量在Swift 2中包含零值,variables,parse-platform,swift2,Variables,Parse Platform,Swift2,我在类的顶部声明了一个变量destinationID。第一次打印显示变量的正确内容,而第二次打印显示的是nil值 有人知道问题出在哪里吗 import UIKit class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate{ var destinationUserID = String() func tableView(tableVie
import UIKit
class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate{
var destinationUserID = String()
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
//Opzoeken wat het bijhorende ID is
let query = PFQuery(className:"_User")
query.whereKey("username", equalTo:selectedUsername)
query.findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
// Do something with the found object
for object in objects! {
self.destinationUserID = object.objectId!
print(self.destinationUserID)
}
print("try 1 : " + self.destinationUserID)
}
print("try 2 : " + self.destinationUserID)
}
}
print(“try 1…”
语句在块内。print(“try 2…”
语句在块外。print语句在后台执行,这意味着在进入print(“try 2…”
)时,搜索可能尚未完成