CoreData & Singleton pattern using NSObjectController
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