Re: How do I know when my Core Data app is up and running?
Re: How do I know when my Core Data app is up and running?
- Subject: Re: How do I know when my Core Data app is up and running?
- From: Paul Collins <email@hidden>
- Date: Sun, 1 Oct 2006 22:24:25 -0700
On Oct 1, 2006, at 1:32 PM, Arthur C. wrote:
When my program starts, all managed objects are fetched, which I
can monitor using the awakeFromFetch method.
Now I would like to get a notification when *all* managed objects
are fetched, and the program is ready to run. At that moment, I
would like to do some initialization code which requires that at
least some, or preferably all managed objects are fetched and ready.
So, is there such a notification, or a method like awakeFromFetch
or applicationDidFinishLaunching which is executed at the right
moment?
Rather than await a notification, you can just start using Core Data
methods.
Fetching is not part of the initialization of Core Data. Core Data
can be considered initialized when an NSManagedObjectContext is
instantiated and receives a -setPersistentStoreCoordinator message.
This is usually done in a -managedObjectContext accessor method,
which you can override (if you subclass NSPersistentDocument) or
modify (if you're using the "Core Data Application" template).
Core Data objects are fetched when you want to do something with
them. If you programmatically fetch all (or some) objects, they are
returned in an NSArray you can do whatever you want with them.
Fetching, like most actions in Core Data, requires an
NSManagedObjectContext, so that ensures you have an "initialized Core
Data."
In a Core Data + Bindings application, there could be automatic
fetching at application startup due to an NSArrayController in
"Entity" mode in the MainMenu nib, or when an NSPersistentDocument is
opened and contents displayed in a window.
Depending or what your "some initialization code" does, it can
probably be run at any reasonable time (such as in -
applicationWillFinishLaunching) by triggering -managedObjectContext
(such as by fetching or inserting objects, or perhaps just calling -
managedObjectContext). If you need to work with the existing objects,
you can execute a fetch request which returns them.
If I've failed to help, try the Core Data FAQ in the Core Data
Programming Guide.
--Paul Collins
_______________________________________________
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