Re: NSArrayController, bindings and NSUserDefaults
Re: NSArrayController, bindings and NSUserDefaults
- Subject: Re: NSArrayController, bindings and NSUserDefaults
- From: Steven Riggs <email@hidden>
- Date: Sun, 09 Nov 2008 13:29:17 -0500
This worked for me...
In interface builder, you will need an Array controller
Mode: Class Class Name:NSMutableDictionary
Content Array bound to Shared User Defaults Controller - controller
key:values - modal key path:yourDefaultsKey
Make sure handles content as a compound value is checked here.
I think you need to archive and unarchive when you read and write each
key in your dictionary.
Good luck,
Steven Riggs
On Nov 9, 2008, at 1:09 PM, Andre Masse wrote:
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 (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden