I've created a "Settings" model for my iPhone app. It only contains two properties and a class method for loading and one instancemethod for saving.
I load it as follows
+ (UserSettings *)getCurrent {
NSUserDefaults *userPrefs = [NSUserDefaults standardUserDefaults];
UserSettings *settings = [UserSettings new];
settings.username = [userPrefs stringForKey:kUserNameKey];
settings.password = [userPrefs stringForKey:kPasswordKey];
[userPrefs release];
return settings;
}
The problem that the handling with the NSUserDefault casts an exception;
-[NSCFArray objectForKey:]: unrecognized selector sent to instance 0x50b220
I have imported my header with the constants which are defined as follows;
#define kUserNameKey @"Username"
#define kPasswordKey @"Password"
(I am aware of keychain and am planning on changing to that later on, but want to solve the userdefaults)