nsmanagedobjectcontext

Best approach to update managed objects from async web services responses?

99封情书 提交于 2019-12-01 11:58:53
I have an NSManagedObjectContext associated to main thread ( mainContext ), where I fetch all the NSManagedObject I show throughout the app. Users don't edit these objects, but I get updates from web services. I periodically perform asynchronous calls to such services, and they "tell" me which of my managed objects have to be deleted (if any), which of them have to be updated with new information (if any), and if I need to insert new objects. So, I need to firstly get the responses of all the services and then check what changes I have to make to the managed objects I already have in my

Coredata performBlock then return the new value

不羁的心 提交于 2019-12-01 11:09:17
How to return the new object saved in coredata if I am using performBlock to save a managedObjectContext? The requirement is, add an entry in coredata, and return it. My code is something like this: //create a privateMOC NSManagedObjectContext *private = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; //set parentContext [private setParentContext:self.coredataManager.managedObjectContext]; __block Detail *object = nil; [private performBlock:^{ //fetch from the db object = [self.coredataManager insertObjectWithEntityName:NSStringFromClass([Detail class])]

Core Data inheritance vs no inheritance

感情迁移 提交于 2019-12-01 09:06:21
问题 i'm having some issues with core data, so i hope that someone will be able to help me :) First problem, i have a data model that looks like this : Entity P (A) <----> Entity R / | \ / /\ \ / / | \ \ C D E F G All my entities inherit from the same entity "P" because they need a common attribute and a common relationship ("A" and "R") The problem i am getting is that core data uses generates only one sqlite table for all the entities when you use inheritance. In my case it means that my

Coredata performBlock then return the new value

天涯浪子 提交于 2019-12-01 08:16:10
问题 How to return the new object saved in coredata if I am using performBlock to save a managedObjectContext? The requirement is, add an entry in coredata, and return it. My code is something like this: //create a privateMOC NSManagedObjectContext *private = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; //set parentContext [private setParentContext:self.coredataManager.managedObjectContext]; __block Detail *object = nil; [private performBlock:^{ //fetch

Illegal relationship between objects in different contexts: but I only have one context?

眉间皱痕 提交于 2019-12-01 04:50:26
I get the following error: 'NSInvalidArgumentException', reason: 'Illegal attempt to establish a relationship 'condition' between objects in different contexts when running my iphone app. The relevant part of my model looks like this: AssessmentTree -has one TreeCrown TreeCrown -has one TreeCrownCondition -has one AssessmentTree TreeCrownCondition -has many TreeCrowns For the sake of context, I'll mention that this part of the model is designed to allow an arborist to record the condition of a tree's crown. It stores a list of options for assessing the tree crown that can also be edited by the

Does NSFetchedResultsController Observe All Changes to Persistent Store?

自作多情 提交于 2019-12-01 04:12:17
My program does work like link below: Update results of NSFetchedResultsController without a new fetch show result of NSFetchedResultsController to UITableView get new object from web service and store it to core data (in same view controller, with RestKit) update table view with notification of NSFetchedResultsController delegate The implementation of NSFetchedResultsControllerDelegate is copied from Apple's Core Data project and my predicated is: [NSPredicate predicateWithFormat:@"isMyTest == TRUE"] If the property update goes from TRUE to FALSE, it removes rows from the tableview (because

Multiple NSEntityDescriptions Claim NSManagedObject Subclass

此生再无相见时 提交于 2019-12-01 02:08:49
I am creating a framework that allows me to use Core Data. In the framework's test target, I have configured a data model named MockModel.xcdatamodeld . It contains a single entity named MockManaged that has a single Date property. So that I can test my logic, I am creating an in-memory store. When I want to validate my saving logic, I create an instance of the in-memory store and use it. However, I keep getting the following output in the console: 2018-08-14 20:35:45.340157-0400 xctest[7529:822360] [error] warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass

Core-Data executeFetchRequest freezes App in a background thread

拜拜、爱过 提交于 2019-12-01 00:13:42
I have a saveMOC which is the direct parent of a mainMOC , and I need for online fetch another tmpMOC in order not to block my UI whilst fetching a ton of records from the Internet. My app freezes. I could narrow it to this very point: fetchedItems = [tmpMOC executeFetchRequest:fetchRequest error:&error]; I tried to enclose this within dispatch_sync , [moc.parentcontext.parentcontext.persistentStoreCoordinator lock/unlock] , [whatevermoc performBlockAndWait] ... I also try to fetch the _mainMOC ... No way... I understand that executeFetchRequest is not thread safe, so, how do I lock whatever I

Singleton managedObjectContext

为君一笑 提交于 2019-11-30 23:35:46
I want to use the singleton UIApplication to access the managedObjectContext of the AppDelegate. But when I write [[[UIApplication sharedApplication] delegate] managedObjectContext] or [[[UIApplication sharedApplication] delegate] __managedObjectContext] it doesn't work. But this line works fine : NSLog(@"Seeking for the AppDelegate : %@", [[[UIApplication sharedApplication] delegate] class]); Do you have a solution ? Niels Try casting it to your actual app delegate implementation, like [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; And to add #import

Multiple NSEntityDescriptions Claim NSManagedObject Subclass

放肆的年华 提交于 2019-11-30 22:21:24
问题 I am creating a framework that allows me to use Core Data. In the framework's test target, I have configured a data model named MockModel.xcdatamodeld . It contains a single entity named MockManaged that has a single Date property. So that I can test my logic, I am creating an in-memory store. When I want to validate my saving logic, I create an instance of the in-memory store and use it. However, I keep getting the following output in the console: 2018-08-14 20:35:45.340157-0400 xctest[7529