nsmanagedobjectcontext

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

妖精的绣舞 提交于 2019-12-02 04:12:34
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 graph (managing the memory footprint) explicitly. Here, I can rely on - (void)refreshObject:

Error creating a separate NSManagedObjectContext

走远了吗. 提交于 2019-12-02 03:22:50
Before getting into my issue, please have a look at this image. Here is the actual data model: I retrieve a set of Records from a web API, create objects out of them, save them in core data and display them in the Today view. By default these records are returned for the current date. The user can tap on Past button to go to a separate view where he can choose a past or future date from a date picker view and view Records for that selected date. This means I have to call the API again passing the selected date, retrieve the data and save that data in core data and display them. When the user

Where should NSManagedObjectContext be created?

ε祈祈猫儿з 提交于 2019-12-01 21:53:11
问题 I've recently been learning about Core Data and specifically how to do inserts with a large number of objects. After learning how to do this and solving a memory leak problem that I met, I wrote the Q&A Memory leak with large Core Data batch insert in Swift. After changing NSManagedObjectContext from a class property to a local variable and also saving inserts in batches rather than one at a time, it worked a lot better. The memory problem cleared up and the speed improved. The code I posted

Context does not save the changes with error 1550

喜夏-厌秋 提交于 2019-12-01 20:59:00
I'm trying to update an entity and save the changes. I'm getting always the following error: The operation couldn’t be completed. (Cocoa error 1550.) Method: - (BOOL) updateEvent:(EventDTO*)eventDTO{ BOOL saved = YES; [self getDataCoreContext]; if (context) { NSError *error; Event *myEvent = (Event *)[context existingObjectWithID:eventDTO.entitysID error:&error]; myEvent.name = eventDTO.name; myEvent.descrptn = eventDTO.description; myEvent.date = eventDTO.date; myEvent.locLatitude = [eventDTO getLatidude]; myEvent.locLongitude = [eventDTO getLongitude]; myEvent.numberOfInvited= [NSNumber

Two persistent stores for one managed object context - possible?

北慕城南 提交于 2019-12-01 18:16:51
I have a fairly complex data model with approximately 10 entities. Some need to be stored to disk and others just need to be available in memory when the application is running. Is it possible to achieve this using two persistent stores for the same managed object context, or should I separate my data models accordingly? Yes, your NSManagedObjectContext uses a NSPersistentStoreCoordinator to determine which store a particular model should use. By setting the persistent store coordinator of your managed object context you can define a custom mapping which uses multiple persistent stores of

Two persistent stores for one managed object context - possible?

这一生的挚爱 提交于 2019-12-01 17:41:13
问题 I have a fairly complex data model with approximately 10 entities. Some need to be stored to disk and others just need to be available in memory when the application is running. Is it possible to achieve this using two persistent stores for the same managed object context, or should I separate my data models accordingly? 回答1: Yes, your NSManagedObjectContext uses a NSPersistentStoreCoordinator to determine which store a particular model should use. By setting the persistent store coordinator

core data update in background

♀尐吖头ヾ 提交于 2019-12-01 14:27:18
I need to basically update my core data in a background thread without blocking UI and save it. After saving should reload table View to view the changes. So for doing this I thought of using dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // Add code here to do background processing NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; self.backgroundManagedObjectContext = context; if(self.managedObjectContext == nil) self.managedObjectContext = [(AppDelegate *)[[UIApplication

Can't create externalDataReference interim file

冷暖自知 提交于 2019-12-01 14:23:49
I use Core Data in my iOS project. I am using multiple contexts in the following way. I have a persisent store context that operates on a private queue and stores changes to the persistent store. I have a main queue context that is the child of persistent store context . All of the FRC s in my app use this context. And finally, if I have to do some changes that I want to save in a batch, I create and use new NSManagedObjectContext s that are children of the main queue context. So I have a chain: DB < persistent store context < main queue context < any other child contexts I have a singleton

NSMergeConflict for NSManagedObject with single ManagedObjectContext

柔情痞子 提交于 2019-12-01 14:12:17
I am working with coreData, I have one to many relationship between folders and files. I am using only one MOC through out my application .I am just passing it to different viewControllers , performing operations like add, edit, delete and then saving. My rootViewController uses NSfetchResultsController, I create folders using it, save and display on my table. saving I do it this way NSError *error; if (![self.managedObjectContext save:&error]) { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate.

How to Get Path of MOMD File in Core Data

…衆ロ難τιáo~ 提交于 2019-12-01 12:06:05
Ey guys, I have seen this question and have used self.managedObjectContent= [NSManagedObjectModel mergedModelFromBundles:nil]; in my code, however, I would like to be able to print a filepath via NSLog to console with the full path of the momd file. Problem is I don't know how to go about extracting the path to the MOMD resource using objective c, when I try logging managedObjectContent to console it ends up printing very lengthy arcane data that I don't even care about. So how would I go about getting only the path of the momd file? Sample code please! Thanks in advance. Solved the problem a