Is NSPersistentStoreCoordinator Thread Safe?

前端 未结 2 556
攒了一身酷
攒了一身酷 2021-02-05 23:04

I\'m working on an iPhone app that uses Core Data. The app makes a call to a web service, parses the resulting XML file, and then creates or modifies Core Data objects in my app

2条回答
  •  面向向阳花
    2021-02-05 23:45

    Zarra later points out that the context locks the store, so it is ok to use the same NSPersistentStoreCoordinator across threads.

    Although the NSPersistentStoreCoordinator is not thread safe either, the NSManagedObjectContext knows how to lock it properly when in use. Therefore, we can attach as many NSManagedObjectContext objects to a single NSPersistentStoreCoordinator as we want without fear of collision.

提交回复
热议问题