我的应用程序和parse.com在swift中出现问题。我试图将所有解析函数分离到自己的文件中,作为需要它们的控制器调用的函数。
以下是代码
的示例class func getUsersInNetwork() -> (users: [String??], names: [String], profilePics: [String])? {
var users: [String??] = []
var names: [String] = []
var profilePics: [String] = []
PFCloud.callFunctionInBackground("getUsersInNetwork", withParameters: [:]) {
(response: AnyObject?, error: NSError?) -> Void in
if error == nil {
var objects = response as! [AnyObject]
for object in objects {
var objectId: String?? = object.objectId
var name = object.objectForKey("firstName") as! String
var imgUrls = object.objectForKey("imgUrls") as! [String]
users.append(objectId)
names.append(name)
profilePics.append(imgUrls[0])
}
} else {
println("Error: \(error!)")
}
}
return (users, names, profilePics)
}
问题是,当我调用此函数时,它返回空列表,因为解析调用尚未完成。我怎样才能解决这个问题。有没有办法用同步请求调用它?