本文介绍了在后台进程之后运行代码 - parse.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 viewController 中有一个 findObjectsInBackgroundWithBlock 方法.现在我想执行代码,但直到这个后台方法完成.我该怎么做?
I have a findObjectsInBackgroundWithBlock method in my viewController. Now i want to execute code, but just until this background method is finished. How can i do that?
我正在使用 swift 编程语言.
I'm using the swift programming lanuage.
推荐答案
parse.com 上的文档和指南很好地涵盖了这一点.但也许您有更具体的问题/场景?
This is pretty well covered in the documentation and guide on parse.com. But maybe you have a more specific question/scenario?
var query = PFQuery(className:"GameScore")
query.whereKey("playerName", equalTo:"Sean Plott")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved (objects!.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
println(object.objectId)
}
}
} else {
// Log details of the failure
println("Error: (error!) (error!.userInfo!)")
}
}
PFUser 到用户名数组的特定版本
specific version for PFUser to array of usernames
var usernames: [String]?
func loadUsernames () {
if let query = PFUser.query() {
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil { // No error - should be good to go
self.userNames = (objects as! [PFUser]).map({$0.username!})
// Call/run any code you like here - remember 'self' keyword
// It will not run until userNames is populated
self.callSomeMethod()
} else { // Error - do something clever
}
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
loadUsernames()
}
这篇关于在后台进程之后运行代码 - parse.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!