Hi,

I'm having difficulties binding (in IB) my application's preferences to NSUserDefaults. It's easy to bind simple values, but not so when using composite objects in an array where each element is an object archived as NSData with NSKeyedArchiver. Further more, when the object has another object for one of its member... At first, I was reading the user defaults myself and populating an array by decoding each object. The NSArrayController was using this array for its content and all worked great. Now, I want to get rid of this intermediate array and bind directly to the user default dictionary. So I removed all binding to the old array and this is where I'm stuck...

In the binding tab in IB, I bind the NSArrayController's controller content to "Shared User Default Controller", used "values" for controller key, "users" (which is the key in the user defaults dictionary) for model key path and NSKeyedUnarchiveFromData for value transformer. This is obviously not the way to go cause I'm getting the following error:

*** -[NSCFArray bytes]: unrecognized selector sent to instance 0x15e03900


Here's the code called from the application controller to set up the defaults:

+ (void) initialize
{
        NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
        GHLoginInfos *loginInfo = [[[GHLoginInfos alloc] init] autorelease];    
        NSImage *img = [NSImage imageNamed:NSImageNameUser];
        NSString *name = NSFullUserName();
GHUser *user = [[GHUser alloc] initWithUserName:name userImage:img loginInfos:loginInfo];
        
        NSData *userAsData = [NSKeyedArchiver archivedDataWithRootObject:user];
        NSMutableArray *users = [NSMutableArray arrayWithObject:userAsData];
        [defaultValues setObject:users forKey:@"users"];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
}

GHUser members are:

NSString *userName;
NSImage *userImage;
GHLoginInfos *loginInfos;

and GHLoginInfos members:
NSString* loginName;
NSString* password;
NSString* host;
NSString* dbName;
NSString* port;

The view contains an NSTableView and NSTextFields displaying the currently selected row content but at this point I'm only trying (without any success) to fill up the table view.

Any help, pointer to tutorial etc appreciated.

Thanks,

Andre Masse
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to