• 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
CoreData & Singleton pattern using NSObjectController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData & Singleton pattern using NSObjectController


  • Subject: CoreData & Singleton pattern using NSObjectController
  • From: Bruno Blondeau <email@hidden>
  • Date: Mon, 18 Jul 2005 09:23:30 +0200

I'm trying to use CoreData to store preferences, using some kind of singleton pattern.

I have a NSObjectController (Entity: Singleton) defined in my Document NIB file.
Singleton has:
prefDictionary (transient), using the trick described in the CoreData documentation so as to link it to prefData
prefData (binary)


Everything is working fine while the application is running. Everything is saved properly to disk too.

However, I'm unable to restore the values properly when the document is open.

It seems the controller can't have a selection in windowControllerDidLoadNib (NO SELECTION MARKER appears whatever I try to do)

Do you have a workaround? Is it a bug in my application? In CoreData?

Bruno



MYDOCUMENT.M

- (id)initWithType:(NSString *)type error:(NSError **)error
{
self = [super initWithType:type error:error];
if (self != nil)
{
// executed only when a document is created
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
[NSEntityDescription insertNewObjectForEntityForName:@"Singleton"
inManagedObjectContext:managedObjectContext];


        [managedObjectContext processPendingChanges];
        [[managedObjectContext undoManager] removeAllActions];
        [self updateChangeCount:NSChangeCleared];
    }
    return self;
}



- (void)windowControllerDidLoadNib:(NSWindowController *)windowController
{
[super windowControllerDidLoadNib:windowController];


    [catController fetch:self];
    [notesController fetch:self];

//    [singletonController prepareContent];  // DOESN'T CHANGE ANYTHING
//    [singletonController fetch:self]; // DOESN'T CHANGE ANYTHING

NSLog([singletonController description]);
NSLog([[singletonController selection] description]);
NSLog( [[[singletonController selection] valueForKeyPath:@"prefDictionary"] description] );
NSLog( [[[singletonController selection] valueForKeyPath:@"prefData"] description] );


    // ==> <NO SELECTION MARKER>
...
}


_______________________________________________ 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
  • Prev by Date: Date Column Resizing
  • Next by Date: NEWBIE - What's the line continuation character
  • Previous by thread: Date Column Resizing
  • Next by thread: NEWBIE - What's the line continuation character
  • Index(es):
    • Date
    • Thread