• 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: Observing Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Observing Core Data


  • Subject: Re: Observing Core Data
  • From: Jim Correia <email@hidden>
  • Date: Tue, 12 Sep 2006 08:52:13 -0400

On Sep 12, 2006, at 8:18 AM, Julio Cesar Silva dos Santos wrote:

5) Now imagine the following situation: The first time the user launches the application, the Persistent Data Store is empty and I would like to detect this and add all the names to the NSArrayController in order to have them available to the user;

6) I thought that adding an observer to Key Path "arrangedObjects.@count" would give me this answer and I would do the following:
if ([[MyController content] count] == 0) {
NSEntityDescription * ed = [NSEntityDescription entityForName:@"VideoSystem" inManagedObjectContext:[self managedObjectContext]];
VideoSystemMO * vmo = [[VideoSystemMO alloc] initWithEntity:ed insertIntoManagedObjectContext:[self managedObjectContext]];
[vmo setVideoSystemName:@"NTSC"];
[MyController addObject:vmo];
}

[...]

10) Then my question is: how can I detect (and when) that the Persistent Data Store is loaded and one of its arrays are empty?

The array controller is the glue that binds your model to your user interface. Since you want to automatically populate the model when certain conditions are met (or aren't, in this case), this is not a controller/view problem. It is strictly a model problem.


What kind of application are you building?

If you are building a CoreData document based application, the documentation tells you how to do this.

<http://developer.apple.com/documentation/Cocoa/Conceptual/ NSPersistentDocumentTutorial/00_Introduction/chapter_1_section_1.html>

If you are building a CoreData application with a central store, and are not using NSPersistentDocument, the basic recipe is

Early in the startup process (-applicationDidFinishLaunching: for example) execute a fetch request for the entity VideoSystem. If you get back 0 instances, pre-populate with the default values.

If you want to avoid re-populating with the default values on the next launch if the user intentionally deletes all of the factory default instances, you can record that you've already done this work one in the store's metadata area.

Jim
_______________________________________________
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


References: 
 >Re: Observing Core Data (From: Matt Neuburg <email@hidden>)
 >Re: Observing Core Data (From: Miguel Sanchez <email@hidden>)
 >Re: Observing Core Data (From: Julio Cesar Silva dos Santos <email@hidden>)

  • Prev by Date: Re: NSArrayController remove:
  • Next by Date: Re: NSArrayController remove:
  • Previous by thread: Re: Observing Core Data
  • Next by thread: Re: How do I get the NSApplication of other running
  • Index(es):
    • Date
    • Thread