0
晚上好!Swift语言:更新分析对象
我创建了一个查询,获取用户名和设备位置7miles内我周围的人的位置,我想更新这些对象每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
*/
}
我正在使用的查询做了所有这些,我只是使用了解析的示例查询,我的问题的关键是我应该如何定期更新对象,我应该创建一个计时器并以这种方式更新它们?还是有更实际的方法? –
查看我在回答中的编辑 –