nsmanagedobjectcontext

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

若如初见. 提交于 2019-12-03 01:48:13
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 context (via UI). Background contexts should be notified about this and handle the situation to prevent

Undoing Core Data insertions that are performed off the main thread

牧云@^-^@ 提交于 2019-12-03 01:32:53
问题 I'm working on some code that uses an NSOperation to import data. I'd like for the user to be able to undo the NSManagedObject instances that are created during the import operation. From what I can tell, it's impossible to use the NSManagedObjectContext -undoManager for any operations that are performed off of the main thread. From the Core Data Programming Guide section on Use Thread Confinement to Support Concurrency , we have these two conditions: Only objectID should be passed between

iPhone iOS how to merge Core Data NSManagedObjectContext?

岁酱吖の 提交于 2019-12-03 00:43:08
I'm trying to download some JSON objects in the background and am doing quite a bit of multi threading. Once the operation completes, I noticed that this assertion fails: NSAssert([user.managedObjectContext isEqual:[AppUser managedObjectContext]],@"Different contexts"); How can I merge changes into the main context defined by [AppUser managedObjectContext] ? Lorenzo B I really suggest you to read the following link on importing-and-displaying-large-data-sets-in-core-data by Marcus Zarra . When you deal with threads, each thread you create needs to have its own context as written in the link

Core Data managed object context design recommendation

耗尽温柔 提交于 2019-12-02 21:05:28
We are working on an Enterprise-level application, which will store tens of thousands of objects with Core Data, and we are having issues on several fronts. Our application has several independent systems which operate on the data when needed. These systems include discovery of items, loading of items, synchronization and UI display. If we design our software correctly, there should be little to none merge conflicts due to the different systems modifying same objects. Each system has its own operation queues, all performing in the background. We wish to keep all object creation and

iOS5 NSManagedObjectContext Concurrency types and how are they used?

安稳与你 提交于 2019-12-02 19:30:47
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 to merge data from Thread B MOC via a save message, thread A would need to subscribe to thread B's MOC

How do I create a child NSManagedObjectContext?

孤者浪人 提交于 2019-12-02 16:25:54
I've seen a few videos / threads that say it's possible to create 'children' MOCs -- MOCs that use other MOCs as their persistant stores. Useful, for example, in a context where you're threading your application, and want to have a single master MOC that can save / rollback the changes that the child threads create. (From what I understand, a MOC and it's managedObjects MUST all be used on the same thread) The question is, how do I create a child MOC? I can't track down the WWDC videos I was watching that introduced them, and everything I"ve seen has been talking about how to use them ONCE

Core Data iOS10: viewContext not receiving updates from newBackgroundContext() with NSFetchResultController

半城伤御伤魂 提交于 2019-12-02 16:16:23
In my application, I have a NSFetchResultController to load Core Data objects in a UITableView. The fetch request associated with this FRC uses the new viewContext property available for the NSPersistentContainer (iOS10). When I select a cell, I pass the Core Data object to a new ViewController. This new VC still uses the viewContext. From this ViewController, I can update the Core Data object from ViewControllers presented modally. To do so, I use newBackgroundContext() for the modal ViewControllers. I can save the update Core Data object without any issue. The problem is that the FRC is not

CoreData could not fulfill a fault for

£可爱£侵袭症+ 提交于 2019-12-02 15:48:14
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, @"Not initialized"); NSError *error = nil; BOOL failed = [self.context hasChanges] && ![self.context

Undoing Core Data insertions that are performed off the main thread

陌路散爱 提交于 2019-12-02 14:57:51
I'm working on some code that uses an NSOperation to import data. I'd like for the user to be able to undo the NSManagedObject instances that are created during the import operation. From what I can tell, it's impossible to use the NSManagedObjectContext -undoManager for any operations that are performed off of the main thread. From the Core Data Programming Guide section on Use Thread Confinement to Support Concurrency , we have these two conditions: Only objectID should be passed between managed object contexts (on separate threads) Managed objects must be saved in a context before the

Multiple contexts in the main thread: why and when use them?

烈酒焚心 提交于 2019-12-02 06:38:26
问题 I'm looking for a simple answer that could highlight rules for using (or avoiding) multiple contexts within the same thread (the main one in my case). Usually, in Core Data, I set up a single main context that is used throughout the application. Then, if I need to perform some background work, I create a context for each background operation I run. Such an approach is valid most of the time. Core Data manages the memory in a perfect manner. But I can also decide to purge some of the object