nsmanagedobjectcontext

Why doesn't NSManagedObject instances hold a strong reference to their NSManagedObjectContext?

旧城冷巷雨未停 提交于 2019-11-29 02:08:25
As pointed out in another question on SO (and the Apple docs ), NSManagedObject instances do not hold a strong reference to the NSManagedObjectContext from which they originated. On first blush, this seems like a strange decision, since NSManagedObject instances are nearly useless without their context , since it leads to confusing bugs such as faults not firing when they should . Can anyone provide some background on why this is the case? Would it be dangerous to implement an NSManagedObject subclass that automatically holds a strong reference to its NSManagedObjectContext ? Edit: thanks to

NSFetchedResultsController doesn't show updates from a different context

醉酒当歌 提交于 2019-11-29 00:45:30
问题 I have an NSFetchedResultsController and a few operations updates managed objects on separate threads via NSOperationQueue . The FRC (with its predicate) looks like this: - (NSFetchedResultsController*)fetchedResultsController { if(fetchedResultsController) return fetchedResultsController; NSManagedObjectContext* mainContext = [self managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:[NSEntityDescription entityForName:@"Check"

Behavior differences between performBlock: and performBlockAndWait:?

て烟熏妆下的殇ゞ 提交于 2019-11-28 16:07:07
I'm creating an NSManagedObjectContext in a private queue to handle data updates I take from files and/or services: NSManagedObjectContext *privateContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; privateContext.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator; Since I'm using a private queue, I don't fully understand the difference between performBlock: and performBlockAndWait: methods... To perform my data updates I'm currently doing this:

Core Data merge two Managed Object Context

做~自己de王妃 提交于 2019-11-28 16:01:08
My Cocoa/Application has a Managed Object Context on the main thread. When I need to update my data my program will: Start a new thread Receive new data from a server Create a new Managed Object Context Send a notification to the main thread in order to merge the two context This is the function that receive the notification on the main thread - (void)loadManagedObjectFromNotification:(NSNotification *)saveNotification { if ([NSThread isMainThread]) { [self.managedObjectContext mergeChangesFromContextDidSaveNotification:saveNotification]; } else { [self performSelectorOnMainThread:@selector

When to use Core Data's NSMainQueueConcurrencyType?

安稳与你 提交于 2019-11-28 15:58:51
问题 Is initializing a NSManagedObjectContext using NSMainQueueConcurrencyType only for the situation where that MOC has a child MOC that was initialized using NSPrivateQueueConcurrencyType ? To give some background: my app has a traditional structure whereby the main table view is driven by a NSFetchedResultsController and data are imported asynchronously from a web service using an NSOperation subclass that has its own MOC. I wasn't sure whether both MOCs in that situation should use

How can I track/observe all changes within a subgraph?

柔情痞子 提交于 2019-11-28 13:41:41
问题 I have a NSManagedObjectContext in which I have a number of subclasses of NSManagedObjects such that some are containers for others. What I'd like to do is watch a top-level object to be notified of any changes to any of its properties, associations, or the properties/associations of any of the objects it contains. Using the context's 'hasChanges' doesn't give me enough granularity. The objects 'isUpdated' method only applies to the given object (and not anything in its associations). Is

Cross-model relationships in NSManagedObjectModel from merged models?

坚强是说给别人听的谎言 提交于 2019-11-28 08:40:02
Is it possible to model relationships between entities that are defined in separate NSManagedObjectModels if the entities are always used within an NSManagedObjectModel that is created by merging the relevant models? For example, say model 1 defines an entity Foo with relationship (one-to-one) toBar and that model 2 defines an entity Bar with a relationship (one-to-one) toFoo . I will build a CoreData stack using -[NSManagedObjectModel mergedModelFromModels] , merging model 1 and model 2. Is there any way to define these relationships either in the data modeler or programatically so that they

What is NSManagedObjectContext's performBlock: used for?

牧云@^-^@ 提交于 2019-11-28 02:46:55
In iOS 5, NSManagedObjectContext has a couple of new methods, performBlock: and performBlockAndWait: . What are these methods actually used for? What do they replace in older versions? What kind of blocks are supposed to be passed to them? How do I decide which to use? If anyone has some examples of their use it would be great. The methods performBlock: and performBlockAndWait: are used to send messages to your NSManagedObjectContext instance if the MOC was initialized using NSPrivateQueueConcurrencyType or NSMainQueueConcurrencyType . If you do anything with one of these context types, such

Core Data not saving transformable NSMutableDictionary

一曲冷凌霜 提交于 2019-11-28 01:22:18
问题 I have two classes: Profile and Config. A Profile contains an NSSet of Config objects. Both Profile and Config are NSManagedObject subclasses. @interface Profile : NSManagedObject @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSSet *configs; - (void)print; @end Here is the Config class @interface Config : NSManagedObject @property (nonatomic, retain) NSString * otherdata; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain)

Core Data nested managed object contexts and frequent deadlocks / freezes

纵然是瞬间 提交于 2019-11-27 17:43:21
I have a problem that is almost identical to the problem described by this person here, but it hasn't get answered: http://www.cocoabuilder.com/archive/cocoa/312683-core-data-nested-managed-object-contexts-and-frequent-deadlocks.html#312683 Here is the problem: I have a parent MOC setup with NSPrivateQueueConcurrencyType and a persistent store coordinator set, it has a child MOC setup with NSMainQueueConcurrencyType. The idea being most of the long hard work and saves can be done on the private MOC freeing the main thread from blocking the UI. Unfortunately I seem to be running into a couple