nsmanagedobjectcontext

Trying to implement master-child Managed Object Context when doing mass delete in Core Data

孤街醉人 提交于 2019-12-10 11:37:00
问题 I am working on a project where I am doing a mass delete of a number of NSManagedObjects (MO) that I retrieve from Core Data. When I iterate through this collection of MO's, I am also retrieving OTHER MO's by calling a fetch method DURING the iteration of the initial collection of MO's. If during this iteration process, an object is found from the fetch request, the MO is deleted. I realize that this is a poor design of the architecture, as these MO's should in fact be having inverse

insertNewObjectForEntityForName:inManagedObjectContext: returning NSNumber bug?

纵饮孤独 提交于 2019-12-10 02:20:50
问题 I'm relatively well versed in CoreData and have been using it for several years with little or no difficulty. For the life of me, I can't figure out why insertNewObjectForEntityForName:inManagedObjectContext: is all of a sudden returning some sort of strange instance of NSNumber. GDB says the returned object is of the correct custom subclass of NSManagedObject, but when I go to print a description of the NSManagedObject itself, I get the following error: *** -[NSCFNumber objectID]:

How to make/use temporary NSManagedObjects?

半世苍凉 提交于 2019-12-09 23:29:10
问题 Simple, common pattern I can't find in Apple's docs: Load a coredata store Download new data, creating objects in memory Save some of the new data to the store (usually "only the new bits / bits that haven't changed") Instead, I can find these alternatives, none of which are correct: Don't create objects in memory (well, this means throwing away everything good about objects. Writing your code using lots of NSDictionary's who serve no purpose except to workaround CoreData's failings. Not

How do I resolve this deadlock that happen ocassionally?

╄→尐↘猪︶ㄣ 提交于 2019-12-09 23:14:41
问题 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]; [_

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

半城伤御伤魂 提交于 2019-12-09 20:17:15
问题 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)

Working with the same NSManagedObjectContext in multiple tabs

半城伤御伤魂 提交于 2019-12-09 14:18:00
问题 I have a tab bar controller with different view controllers all using the same managed object context, being set up as follows: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RootViewController *rootVC = [[RootViewController alloc] initWithStyle:UITableViewStyleGrouped]; rootViewController.managedObjectContext = self.managedObjectContext; UINavigationController *rootNavCon = [[UINavigationController alloc]

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

三世轮回 提交于 2019-12-09 03:11:14
问题 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

ViewContext not receiving updates from newBackgroundContext()

风格不统一 提交于 2019-12-08 16:43:21
问题 There is a similar question in stack overflow already but it doesn't work for me. There is a use case in my application where I have to observe the database changes to perform some operation. To receive updates I subscribed to NSManagedObjectContextObjectsDidChange notification (for ViewContext) and also I turned on automaticallyMergesChangesFromParent . But, if I update or delete the object on some other context (using newBackgroundContext() ), I don’t receive object did change notification

How to use ManagedObjectContext with threads

为君一笑 提交于 2019-12-08 08:21:16
问题 This is probably a very straight forward application, but I am new to Objective-C (coming from Java) and the whole memory management and "EXC_BAD_ACCESS" errors are breaking my heart. I have a normal NavigationController iPhone App, with Core Data. in the AppDelegate the NSManagedObjectContext is created and passed to the RootViewController. A view things are looked up directly from the main thread to populate the table, and that seems to work fine. The App is somekind of RSS-type reader, so

Creating a NSManagedObjectContext on a private/background queue: how to do?

元气小坏坏 提交于 2019-12-08 07:42:55
问题 I am confused about how to create a MOC on other threads than the main thread. On one hand, in the doc, one can read A consequence of this is that a context assumes the default owner is the thread or queue that allocated it—this is determined by the thread that calls its init method. You should not, therefore, initialize a context on one thread then pass it to a different thread. But on the other hand, I have seen code where an auxiliary MOC is created the following way, on the main thread :