nsmanagedobjectcontext

Core Data Multiple Threads - View Controller Not Updating

牧云@^-^@ 提交于 2019-12-11 14:10:09
问题 I am trying to use Core Data in an app I'm working on; in the app delegate this code kicks off the import of data from a downloaded JSON file. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //setup app window, etc. BECDRefreshOperation *loadData = [[BECDRefreshOperation alloc] initWithStoreCoordinator:self.persistentStoreCoordinator]; [queue addOperation:loadData]; //queue is an NSOperationQueue return YES; } BECDRefreshOperation

Why does an unsaved managedObject lose its managedObjectContext

女生的网名这么多〃 提交于 2019-12-11 12:38:02
问题 Currently, I am developing an app to book cars. All booking related data are stored in an entity 'Bookings'. As some attributes of 'Bookings' or relationships between 'Bookings' and other enties are mandatory I decided to add all managedObjects of entity 'Bookings' to their own managedObjectContext. This context will also be stored in a separate variable to avoid losing it. This works fine unless I'll sign (enterprise store or adhoc) my app and deploy it. ARC is enabled. Class Bookings

Avoid fetching deleted NSManagedObjects

≡放荡痞女 提交于 2019-12-11 08:38:38
问题 Using NSFetchRequest , is it possible to avoid fetching a NSManagedObject that has been or will be deleted? I know it's possible to check -isDeleted or if -managedObjectContext returns nil, but is there a way to do this in the database layer? 回答1: Technically, if the object is truly deleted it will not show up at the database layer. What are the symptoms of the problem presenting as? 来源: https://stackoverflow.com/questions/9415071/avoid-fetching-deleted-nsmanagedobjects

EXC_BAD_ACCESS crash when updating NSManagedObject

非 Y 不嫁゛ 提交于 2019-12-11 06:25:30
问题 I have an application that pulls JSON data from a server, parses the data into NSManagedObject subclasses and these NSManagedObject subclasses are then used as properties in various view controllers. The trouble I'm having is that at some point in the future the data on the server will change and this will trigger an update pull request. When attempting to update the NSManagedObject subclasses, the app is crashing if the user then attempts to modify NSManagedObject via the UI by e.g.

Check if managedobjectcontext is empty?

巧了我就是萌 提交于 2019-12-11 04:51:42
问题 In my application I want to make it so that when the user opens the application and there are no objects, i want it to add an object to the first section of the table view. I know in my App Delegate in the method: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { I can do something like this: if (XXXXXX){ NSManagedObjectContext *context = self.managedObjectContext; NSManagedObject *startingTask = [NSEntityDescription

Parent MOC get changes with empty data from child MOC

空扰寡人 提交于 2019-12-10 21:48:35
问题 I'm stuck on this problem with CoreData and Parent-Child MOCs: when adding objects to child MOC, saving them and saving the parent MOC all the objects gets their attributes reset to defaultValue. I pasted here the logs from the two MOCs, specifically are the "stringAttribute" and "date" attributes that in these log are reset. I searched for this problem everywhere but i didn't find anything, I also looked at lots of implementation of Parent-Child MOCs but I can't figure out what I'm doing

CoreData child contexts, NSFetchedResultsController and main thread

一个人想着一个人 提交于 2019-12-10 16:52:26
问题 Following this excellent post by Olivier Drobnik, I've implemented the three-layer CoreData stack proposed by CoreData guru Marcus S. Zarra: The only difference from this diagram and my code is that I only use one Temporary Background MOC, in order to avoid duplicates when inserting objects in several temp MOCs. Here's my context initialisation code: #pragma mark - NSManagedObjectContexts + (NSManagedObjectContext *)privateManagedObjectContext { if (!_privateManagedObjectContext) { // Setup

Core Data: NSObjectID and NSTemporaryObjectID leaks

橙三吉。 提交于 2019-12-10 15:51:15
问题 Before I send my app to the App Store I like to check it for memory leaks and other fishy stuff with instruments. There is one Core Data issue that I can't seem to solve, so I've decided to create a small test app to illustrate the problem. What's the problem? When I save an entity in a (child) NSManagedObjectContext it is propagated to its parent NSManagedObjectContext. During this process Core Data creates internal instances of _NSObjectID and NSTemporaryObjectID . For some reason these

How to get the ID of an object saved to Core Data's managed object context?

放肆的年华 提交于 2019-12-10 14:55:25
问题 I have this code: NSEntityDescription *userEntity = [[[engine managedObjectModel] entitiesByName] objectForKey:@"User"]; User *user = [[User alloc] initWithEntity:userEntity insertIntoManagedObjectContext:[engine managedObjectContext]]; and I want to know the id of the object inserted to the managed object context. How can i get that? Will that id remain the same for that object's lifetime or will it persist to the sqlLite database beneath this and be something that can be used to uniquely

NSFetchedResultsController misses updates on merged NSManagedObjectContext

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 13:26:50
问题 I have two managed object contexts, A and B. These two contexts are kept in sync by merging changes from one to the other whenever they're saved (by monitoring NSManagedObjectContextDidSaveNotification ). I've verified that changes to A and B are merging properly. I have an NSFetchedResultsController monitoring updates to B. I find that certain updates to A do not result in the nsfrc firing on B. When a new managed object is created and added to A with the attributes the nsfrc is looking for