nsmanagedobjectcontext

Cross-model relationships in NSManagedObjectModel from merged models?

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 Ba...

Core Data: editing object from detail view

I'm just starting out with Core Data and I have an iPhone Core Data project set up in a master-detail view system. The master view contains items, and the detail view lets you edit the properties of the selected item. I'm looking for the best options in order to implement the editing. Would I pass along the NSManagedObjectContext to the...

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

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 ...

Why might changes be populated from one NSManagedObjectContext to another without an explicit merge?

I'm working on an object import feature that utilizes multiple threads/NSManagedObjectContexts, using http://www.mac-developer-network.com/columns/coredata/may2009/ as my guide (note that I am developing for iPhone). For some reason, when I save one of my contexts the other is immediately updated with the changes, even though I have com...

NSManagedObjectContext losing data after 2nd save

I have a class called DataRequest, which handles downloading data from a web service via NSURLRequest, parsing the results and stuffing data into a NSManagedObject, and saving it. It contains the fowlling: @property (nonatomic, retain) id DataControllerProtocol dataController; I also have a class called DataController, which encapsul...

Diference between get Object using FetchResultController and ManagedObjectContext

What's the difference between get elements from Core Data with FetchResultController or ManagedObjectContext?? 1) FetchResultController NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:[NSEntityDescription entityForName:@"Item" inManagedObjectContext: managedObjectContext]]; NSSortDescriptor *sor...

NSContextManagedObject - Problem Accessing it

I have tab bar navigation application and The problem is that in my root controller I am able to set its NSContextManagedObject to the app delegates...However when I try to do the same on the other controller the application freezes... This only happens in the ViewDidLoad but thats where I need to set it so I can fetch the data Im acce...

How to not persist NSManagedObjects retrieved from NSManagedObjectContext

Hi I parse an xml file containing books, for each new node I go: Book *book = (Book*)[NSEntityDescription insertNewObjectForEntityForName:@"Book" inManagedObjectContext:managedObjectContext]; To obtain an NSManagedObject of my Core Data Book Entity, I then proceed to populate the managed Book object with data, add it to an array, rin...

Setting a property value on each of the results in a FetchedResults set

Hi On my Core Data Entity "Book" i have a boolean property, 'wasViewed' (NSNumber numberWithBool) that tells me if the Book was "viewed". I would like to implement a sort of "reset" this property for all my NSManagedObjects "Book". So that I can set them all to NO between sessions. I use an NSPredicate to retrieve all the Books like th...

coredata using old file version on device

This is a follow on from my previous problems here. Resetting the simulator solved all my troubles before, and I've gone on to complete my App. I now have the exact same problem when installing the app onto my iPhone device. It picks up an old version of my database, which doesn't have the second entity in it, and crashes when I try to ...

Iterate through NSManagedObjectContext objects?

I want to iterate through all of the objects in my NSManagedObjectContext, and update them manually. Then, every managed object should be updated. What's the best way to do this? ...

insertNewObjectForEntityForName: inManagedObjectContext: returning NSNumber bug?

I'm relatively well versed in CoreData and have been using it for several years with little or no difficulty. All of a sudden I'm now dumbfounded by an error. 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 sa...

insertNewObjectForEntityForName:inManagedObjectContext: returning NSNumber bug?

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 s...

Core Data performance deleteObject and save managed object context

I am trying to figure out the best way to bulk delete objects inside of my Core Data database. I have some objects with a parent/child relationship. At times I need to "refresh" the parent object by clearing out all of the existing children objects and adding new ones to Core Data. The 'delete all' portion of this operation is where I...

How do you delete a core data entry from the detail view?

I am working with an app similar to apple's core data recipes sample code. I want to be able to delete the entry from the detail view, much like apple's contacts app. The code below is deleting the 1st entry and not the selected entry. Not sure what I am doing wrong. NSIndexPath *indexPath = [myTableView indexPathForSelectedRow]; NSM...

NSManagedObjectContextDidSaveNotification just called once in application lifetime

Hi all, I have a problem with two contexts. There is the default manged object context and an import context wich is used for imports. When the import context saves its date a notification is send to merge the changes with the default context: here is the code - (void)updateCompleted { [[NSNotificationCenter defaultCenter] addObserver:...

May a NSManagedObjectContext re-fault objects automatically?

I am trying to create an application which allows background threads to update core data objects while the user might be reading the same data. My approach to this would be to use multiple NSManagedObjectContexts and then before a background thread does a -save: operation, I fetch the object the user is currently working on and fire the...

Is NSManagedObjectContext autosaved or am I looking at NSFetchedResultsController's cache?

I'm developing an iPhone app where I use a NSFetchedResultsController in the main table view controller. I create it like this in the viewDidload of the main table view controller: NSSortDescriptor *sortDescriptorDate = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES]; NSSortDescriptor *sortDescriptorTime = [[NSSortDescript...

Losing NSManaged Objects in my Application

I've been doing quite a bit of work on a fun little iPhone app. At one point, I get a bunch of player objects from my Persistant store, and then display them on the screen. I also have the options of adding new player objects (their just custom UIButtons) and removing selected players. However, I believe I'm running into some memory ma...

How do I copy or move an NSManagedObject from one context to another?

I have what I assume is a fairly standard setup, with one scratchpad MOC which is never saved (containing a bunch of objects downloaded from the web) and another permanent MOC which persists objects. When the user selects an object from scratchMOC to add to her library, I want to either 1) remove the object from scratchMOC and insert int...