我正在学习iOS的并发编程.到目前为止,我已经读过NSOperation/NSOperationQueue和GCD.使用NSOperationQueueover 的原因是什么GCD,反之亦然?
听起来像是两者,GCD并从用户那里NSOperationQueue抽象出明确的创造NSThreads.然而这两种方法之间的关系对我来说并不清楚,所以任何反馈都要赞赏!
concurrency nsoperation nsoperationqueue grand-central-dispatch ios
我相信我遇到了一个问题,我的闭包发生在后台线程上,而我的UITableView的更新速度不够快.我正在调用一个REST服务,在我的关闭中我有一个tableView.reloadData()电话,但这需要几秒钟才能完成.如何使数据重新加载速度更快(可能在主线程上?)
REST查询功能 - 使用SwiftyJSON库进行解码
func asyncFlightsQuery() {
var url : String = "http://127.0.0.1:5000/flights"
var request : NSMutableURLRequest = NSMutableURLRequest()
request.URL = NSURL(string: url)
request.HTTPMethod = "GET"
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response:NSURLResponse!, networkData: NSData!, error: NSError!) -> Void in
var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil
// Parse with SwiftyJSON
let json = JSON(data: networkData)
// Empty out Results array
self.resultArray = []
// Populate Results Array
for (key: String, subJson: JSON) in json["flights"] {
print ("KEY: \(key) ")
print (subJson["flightId"]) …Run Code Online (Sandbox Code Playgroud) 哪些任务更适合使用NSOperation,而不是GCD在为iPhone编程时使用?
对我来说,他们似乎做同样的事情.我看不出一方面的优势和劣势.
我是GCD和线程的新手.我已经完成了教程并且非常困惑.有人可以用简单的话来解释.请不要建议苹果开发者链接..
提前致谢 !
iphone multithreading nsoperationqueue grand-central-dispatch nsinvocation
ios ×3
nsoperation ×2
cocoa-touch ×1
concurrency ×1
iphone ×1
nsinvocation ×1
reloaddata ×1
swift ×1
uitableview ×1