1
我有一個私人的NSManagedObjectContext
隊列,我用它將實體保存到核心數據。保存完成後,我想發出NSNotification。但是,它似乎不喜歡我從私人隊列發出通知。這是我的私人隊列代碼:如何調用主線程上的更新
let parentManagedContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext!
let privateManagedContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType)
privateManagedContext.persistentStoreCoordinator = parentManagedContext.persistentStoreCoordinator
privateManagedContext.performBlock {
...
// Save the entity
do {
try privateManagedContext.save()
// Send out NSNotification here
}
}
如何添加內performBlock
塊主線程上運行?