• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data entities not getting loaded into MOC when opening file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data entities not getting loaded into MOC when opening file


  • Subject: Re: Core Data entities not getting loaded into MOC when opening file
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 10 Jul 2006 00:49:45 -0700

On Jul 9, 2006, at 11:50 PM, Andrew Madsen wrote:

I've got a document-based core data app with a relatively simple data model. I'm seeing a problem where some entities get loaded properly into the MOC when I open an XML file saved by the app.

Just to be clear: Do you fetch the entity whose instances (not "entities") you want to access? You need to either issue a fetch request or traverse a relationship to actually access saved instances of your entities. They are not automatically "loaded" into a context when a persistent store is added to a persistent store coordinator.


However, others don't get loaded. They are visible in the XML file, but the result of a [managedObjectModel registeredObjects] contains the following:

(entity: stationInfo; id: 0x3aea20 <x-coredata://8A66BB3D- DF6F-45D1-8348-0E404838F6C2/stationInfo/p103> ; data: <fault>)

This looks like a normal Core Data fault. What happens when you try to access one of its properties?


stationInfo is the main entity I'm concerned about that doesn't get loaded (the others are related entities). There is only one stationInfo entity per MyDocument instance, and it is one of the instance variables of MyDocument (in addition to having a NSObjectController controlling it). If I do something like NSLog (@"%@", [self myStationInfo]) within MyDocument, the output of the NSLog function is <NULL>.

Just having an instance variable and an object controller bound to that key isn't sufficient to get an instance of your entity upon opening a document. You also need to fetch using the entity and assign one of the resulting instances (if any) to your instance variable.


I can't figure out what would MyDocument to load some of the entities in the XML file, but not others.

Do you have an NSArrayController that is in entity mode, is bound to an NSManagedObjectContext, does not have its content bound, and is set to automatically prepare content? An NSArrayController configured that way will perform a fetch against the context it's bound to and populate itself with the result as a developer convenience.


An NSObjectController does not perform such a fetch. (After all, what should it do if the fetch returns no objects, or returns more than one?) You'll need to perform the fetch yourself when your document is opened and set the instance variable you want to bind your NSObjectController's content to appropriately.

  -- Chris

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Core Data entities not getting loaded into MOC when opening file
      • From: Andrew Madsen <email@hidden>
References: 
 >Core Data entities not getting loaded into MOC when opening file (From: Andrew Madsen <email@hidden>)

  • Prev by Date: Re: where have all the IVARS gone? (long time passing...)
  • Next by Date: NSOutputStream copy
  • Previous by thread: Core Data entities not getting loaded into MOC when opening file
  • Next by thread: Re: Core Data entities not getting loaded into MOC when opening file
  • Index(es):
    • Date
    • Thread