我正在尝试构建从JSON文件接收消息的简单聊天
所以我认为我应该每秒更新一次我的功能以检查是否有新消息,但我认为这是不对的,因为它会增加无用请求的数量。
这是我的代码
我使用这些库
import Alamofire
import SwiftyJSON
这是我的功能
func didchat(){
Alamofire.request(.GET, "http://www.elofight.com/test.json").responseJSON { (responseData) -> Void in
self.reciveResponse = JSON(responseData.result.value!)
print(self.reciveResponse)
}
}
这是我的函数,每隔1秒调用一次这个json文件
override func viewDidLoad() {
super.viewDidLoad()
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(ViewChatViewController.didchat), userInfo: nil, repeats: true)
}
对此有何建议?