0
我正在使用客戶端 - 服務器應用程序。我發送請求後,得到響應去backgound線程解析數據,所有數據解析後,我要去主線程。在領域事務中寫入的所有數據都存在於後臺線程中,但在主線程中爲空。這是我的代碼部分: 在開始我有20個對象使用GCD的領域
Alamofire.request(.GET, urlRequest).responseJSON(completionHandler: { response in
guard let dictionary = response.result.value as? [String : AnyObject]
else {
completion(response: false)
return
}
if dictionary["status"] != nil {
completion(response: false)
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
print("\(NSDate()) start parse feeds with offset")
self.parseArticle(dictionary, data: [])
print("\(NSDate()) finish parse feeds with offset")
UserSession.feedsLoaded = true
//here I have 40 objects
dispatch_async(dispatch_get_main_queue(), {
//here I have again 20 objects, which I had at start
completion(response: true)
})
})
})
func parseArticle(dictionary : [String : AnyObject], data : [String]) {
var startData = data
var endData : [String] = []
let realm = try! Realm()
let _ = try? realm.write() {here is the code of my parser}}
,在後臺線程COMMITED不會出現在主線程領域數據的問題,我該怎麼管理呢?
是什麼問題?請更新您的信息 – UmNyobe
問題是,數據添加到領域的位置在哪裏? –