在后台进程后运行代码-parse.com [英] Run code after a background process - parse.com
本文介绍了在后台进程后运行代码-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?
我正在使用快速编程设备.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文