首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swift语言:更新解析对象

Swift语言:更新解析对象
EN

Stack Overflow用户
提问于 2015-05-07 14:58:38
回答 1查看 554关注 0票数 0

晚上好,程序员们!

我创建了一个查询来获取我周围距离设备位置7英里的人的用户名和位置,我想每5-10秒更新一次这些对象(我还没有决定)。这方面的最佳实践是什么?我应该创建一个NSTimer()并以这种方式调用它吗?请帮帮我!!

代码语言:javascript
复制
 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

  */

  }
EN

回答 1

Stack Overflow用户

发布于 2015-05-07 15:03:00

尝试在查询中添加whereKey:nearGeoPoint:withinMiles:,该查询将查找距离您的位置7英里内的对象

For further details for that check out this link

当您在每次查询后找到数据时,则删除所有以前的数据,并用新数据替换它,然后刷新视图。

NSTimer可能是个不错的选择。甚至我也使用计时器在后台每隔5分钟同步一次,它对我来说工作得很好。

希望这能对你有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30093996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档