简体   繁体   中英

Core Data Concurrency on iOS 9

If I create a NSManagedObjectContext on the main thread with NSMainQueueConcurrencyType must I use performBlock() method for all the save and performFetch methods. IE is it possible to do the following:

do {
    managedObjectContext.save()
} catch let error as NSError {
    print(error)
}

or should I always do this:

managedObjectContext.performBlock({
    do {
        managedObjectContext.save()
    } catch let error as NSError {
        print(error)
    }
})

If I understand the documentation correctly I always have to use performBlock() or performBlockAndWait() but in the template code from XCode 7 they are not using blocks. Any help is appreciated!

如果您已经在主线程中,有一个NSMainQueueConcurrencyType情况下,你不需要使用performBlock

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM