晚上好编码员!
我创建了一个查询,获取设备位置 7 英里内我周围人的用户名和位置,我想每 5-10 秒更新一次这些对象(我还没有决定)。对此的最佳做法是什么?我应该创建一个NSTimer()
并这样称呼它吗?请帮忙!!
var timer = NSTimer()
override func viewDidLoad() {
super.viewDidLoad()
timer == NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "queryFunc", userInfo: nil, repeats: true)
}
func queryFunc() {
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.
NSLog("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
for object in objects { NSLog("%@", object.objectId)
}
} else {
// Log details of the failure
NSLog("Error: %@ %@", error, error.userInfo!)
}
}
/*
This is just an example query, the point of this is the timer and how to update objects periodically
*/
}