nsmanagedobjectcontext

How do I resolve this deadlock that happen ocassionally?

拈花ヽ惹草 提交于 2019-12-04 19:29:24
I have one managedObjectContext with concurency type of NSMainQueueConcurrencyType + (NSManagedObjectContext *)managedObjectContextMainThread { static NSManagedObjectContext *__managedObjectContext=nil; @synchronized(self) { if (__managedObjectContext != nil) { } else { NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { __managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; [__managedObjectContext setPersistentStoreCoordinator:coordinator]; } } } return __managedObjectContext; } The

How to handle saving on child context but the objected is already deleted in parent context?

…衆ロ難τιáo~ 提交于 2019-12-04 17:09:59
I have core data nested contexts setup. Main queue context for UI and saving to SQLite persistent store. Private queue context for syncing data with the web service. My problem is the syncing process can take a long time and there are the chance that the syncing object is deleted in the Main queue context. When the private queue is saved, it will crash with the "Core Data could not fulfill faulted" exception. Do you have any suggestion on how to check this issue or the way to configure the context for handle this case? There is no magic behind nested contexts. They don't solve a lot of

Identifying which fields have changed before CoreData saves

半腔热情 提交于 2019-12-04 16:58:08
问题 //set up notifications [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataChanged:) name:NSManagedObjectContextDidSaveNotification object:context]; //later - (void)dataChanged:(NSNotification *)notification{ NSDictionary *info = notification.userInfo; NSSet *insertedObjects = [info objectForKey:NSInsertedObjectsKey]; NSSet *deletedObjects = [info objectForKey:NSDeletedObjectsKey]; NSSet *updatedObjects = [info objectForKey:NSUpdatedObjectsKey]; Is there anyway to

How to avoid the UI freeze while a Managed Object Context is saving?

99封情书 提交于 2019-12-04 16:06:20
I want to implement a UI-responsive downloading and parsing of a large data set, saving it with Core Data. My setup: I display the downloaded content in a custom view controller. I don't use a NSFetchedResultsController. There are 3 MOCs: masterMOC (responsible for saving to disk, NSPrivateQueueConcurrencyType) mainMOC (used by UI, NSMainQueueConcurrencyType, a child of the masterMOC) backgroundMOC (responsible for the import from JSON, created in a separate thread, a child of the masterMOC) I am importing in batches - every 50 items I perform the MOC saving in the following way: NSError

Strange behavior when using child/parent NSManagedObjectContext

 ̄綄美尐妖づ 提交于 2019-12-04 13:47: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*

NSFetchedResultsController not firing delegate method after merging update from background thread

安稳与你 提交于 2019-12-04 13:20:56
I have an NSFetchedResultsController and a few operations that inserts and updates managed objects on separate threads via NSOperationQueue. The FRC looks like this, note that I have set the cache to nil: [NSFetchedResultsController deleteCacheWithName:nil]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil]; Each threaded operation has its own managed object context and fires mergeChangesFromContextDidSaveNotification to the main MOC each

How to share an entity between two different core data models

这一生的挚爱 提交于 2019-12-04 11:00:46
I'm wondering how to share an entity between two different core data models? For example, I have a " Universe " model which describes a " WorldData " with its " CountryData ". And in another hand, I have a "Population" model which describes a " HumanData " with its " CountryData ". I definitely want to keep my models separated. Thanks in advance. Have you checked the Core Data Guide ? Managing relationships between entities is pretty basic. If you want to manage a relationship between your Universe entities and your Population entities, you should describe them in the same model. Off the top

Core Data: should I be fetching objects from the parent context or does the child context have the same objects as the parent?

痴心易碎 提交于 2019-12-04 07:54:05
I am slightly confused about parent/child contexts for ManagedObjectContext . When I setup a child context and set the parent context, does the child context contain all the objects of the parent context? I am using the stock Core Data methods that get created in the AppDelegate , but I changed the ConcurrencyQueue to main. In my method that is supposed to update the db: Create child context, set parent context Perform block on child context Fetch from parent context Create or update object in child context Call save on child context Have Notification listener to handle child context saves

Core data Multi level parent - Child context

穿精又带淫゛_ 提交于 2019-12-04 07:09:47
In my app I have UITableViewController that shows event list. This controller uses ManagedObjectContext Say ParentContext . Now if any Event is selected, then a detailed View Controller is shown where users can edit the details of Event. So i have created a child context say, ChildContext with type "NSPrivateQueueConcurrencyType" ChildContext whose parent Context is "ParentContext". My code is: NSManagedObjectContext *childContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; childContext.parentContext = self.context ; Now again there are some fields

Objective c - Core Data saving approach

不打扰是莪最后的温柔 提交于 2019-12-04 06:44:17
问题 I have some NSManagedObject subclass in my app, and I'm trying to understand when and how to save changes. I will try to explain myself, for example class A is NSManagedObject subclass. During app life cycle I do: App launched ... Create an instance of class A ... Change some properties of A instance ... App go to background ... App becomes active again ... Change some more properties of A instance ... App terminates When do I need to call [context save:] ?? Do I call it after every change in