Core Data - sharing NSManagedObjects among multiple threads

前端 未结 2 756
执笔经年
执笔经年 2021-01-13 10:35

I suffered all the consequences of using a single MOC in multiple threads - my app crashes at random points because the MOC is created in the main thread and I also use it t

2条回答
  •  生来不讨喜
    2021-01-13 10:46

    If you are only supporting iOS 5 and above you don't need to deal with NSManagedObjectID and merging contexts anymore. You can use the new concurrency types of NSManagedObjectContext instead. Then do your operations within managedObjectContext:performBlock and they will be merged automatically.

    See the answer from svena here for more information: Core Data and Concurrency using NSOperationQueues

提交回复
热议问题