nsmanagedobjectcontext

Core Data concurrency queue style MOC getters thread safety

霸气de小男生 提交于 2019-12-03 13:29:06
I am really confused by the following paragraph straight from the NSManagedObjectContext documentation : Setter methods on queue-based managed object contexts are thread-safe. You can invoke these methods directly on any thread. The big question is setters methods on the ManagedObjectContext but NOT in the ManagedObjects owned by this context? or is it on both?. Specifically if for a private queue MOC object something like this: [privateContext setPersistentStoreCoordinator:self.persistentStoreCoordinator]; Would be thread safe regardless of the thread executing this line but would something

Saving Single CoreData Entity (Not the Whole Context) While Keeping NSFetchedResultController Functionality

邮差的信 提交于 2019-12-03 12:38:55
Phew, sorry for the long title. I have a single Managed Object Context where I am storing songs derived from two different locations. I get some of the songs from the persistent storage on the phone (using Core Data), and I pull some of the songs from an online database. Both of the songs are of the same MananagedObject subclass. I would like both of these songs to be in a single context because I would like them both to show up on a table view connected with an NSFetchedResultsController. The problem occurs when I would like to save one of the songs. I don't want to save all of the songs that

How to correctly propagate delete from main thread's NSManagedObjectContext to child context on a background thread?

本秂侑毒 提交于 2019-12-03 10:12:12
问题 I'm trying to figure out how to solve the following situation There's a main thread NSManagedObjectContext with NSMainQueueConcurrencyType . It spawns several background threads giving them the NSManagedObjectID of some object they will work on. Background threads perform some work (e.g. send the object data to the server, receive response and update the object accordingly). Threads use child contexts with NSConfinenmentConcurrencyType Meanwhile the user deletes the object from main thread's

Strange behavior when using child/parent NSManagedObjectContext

不想你离开。 提交于 2019-12-03 08:32:28
I'm developing an application where I need to both calculate things (multiple seconds operations) and write things (sync data with a server) on a background thread. Because of this I use two NSManagedObjectContexts (MOC), a child and a parent, and these must always be in sync. To make sure they are in sync I always edit/add data to the child MOC so it gets pushed to the main MOC with the following pattern: [childMOC performBlock:^{ MyObject *myObject = *create new object in childMOC* [childMOC save:&error]; [mainMOC performBlock:^{ [mainMOC save:&error]; // Is this mandatory to make it work

iOS5 NSManagedObjectContext Concurrency types and how are they used?

天大地大妈咪最大 提交于 2019-12-03 06:04:48
问题 Literature seems a bit sparse at the moment about the new NSManagedObjectContext concurrency types. Aside from the WWDC 2011 vids and some other info I picked up along the way, I'm still having a hard time grasping how each concurrency type is used. Below is how I'm interpreting each type. Please correct me if I'm understanding anything incorrectly. NSConfinementConcurrencyType This type has been the norm over the last few years. MOC's are shielded from each thread. So if thread A MOC wants

iOS RestKit can not save local entity to database

本秂侑毒 提交于 2019-12-03 05:51:51
I am using RestKit 0.20 to parse JSON data and save to database. THere is a mapped entity SchoolClass, which is handled by RestKit and saves fine. I have another entity called MyClass, which stores the classes I have selected. This one is only local on the device. Here is the code I create and save the MyClass entity NSManagedObjectContext *managedObjCtx = [RKManagedObjectStore defaultStore].mainQueueManagedObjectContext; MyClass* course = [managedObjCtx insertNewObjectForEntityForName:@"MyClass"]; .. set the data for course here NSError *executeError = nil; if(![managedObjCtx save:

How to remove a core data persistent store

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 04:22:16
I need to delete my persistent store (doing it object by object is not practical because I have over 100,000 objects). I've tried this: - (IBAction)resetDatabase:(id)sender { NSPersistentStore* store = [[__persistentStoreCoordinator persistentStores] lastObject]; NSError *error = nil; NSURL *storeURL = store.URL; // release context and model [__managedObjectContext release]; [__managedObjectModel release]; __managedObjectModel = nil; __managedObjectContext = nil; [__persistentStoreCoordinator removePersistentStore:store error:nil]; [__persistentStoreCoordinator release]; _

CoreData could not fulfill a fault for

本小妞迷上赌 提交于 2019-12-03 03:37:54
问题 I have a really annoying problem, which I just can't seem to get fixed. I have a view when I send a message that gets saved to the Core Data, when thats done it asked the database for a random message (sentence) and saved that as well to an other row in the database. If I do the last part hardcoded, without fetching data from the DB, it works all fine and dandy, but as soon as I fetch the random row from the DB it goes crazy. In my AppDelegate.m: - (void)save { NSAssert(self.context != nil, @

Changes saved from one NSManagedObjectContext doesn't reflect on main NSManagedObjectContext

杀马特。学长 韩版系。学妹 提交于 2019-12-03 03:10:30
I have a main NSManagedObjectContext that's created in the appDelegate . Now, I'm using another NSManagedObjectContext for editing/adding new objects without affecting the main NSManagedObjectContext , until I save them. When I save the second NSManagedObjectContext , the changes are not reflected in the main NSManagedObjectContext , yet if I open the .sqlite database from simulator, the changes have been saved correctly into the .sqlite database. It doesn't matter if I fetch the data again, or even if I create a third NSManagedObjectContext , I cannot see those changes from the second

Core Data privateQueue performBlockAndWait deadlock while accessing relationship

你说的曾经没有我的故事 提交于 2019-12-03 02:52:21
This topic has been discussed at many forum, but I am still not able to fully understand how performBlockAndWait actually works. As per my understanding, context.performBlockAndWait(block: () -> Void) will perform the block in its own queue while blocking the caller thread. Documentation says that: You group “standard” messages to send to the context within a block to pass to one of these methods. What are the "standard" messages? It also says that: Setter methods on queue-based managed object contexts are thread-safe. You can invoke these methods directly on any thread. Does that mean that I