registerDefaults error and NSCoding protocol
-
Hi,
Question about registering defaults - I'd assumed the following would
be valid, assuming that GuideSettings implements the NSCoding protocol
- but my app doesn't like this and throws a bad access exception in
CFRetain when I run this code:
The bit that falls over is the registerDefaults: call - the stack
track being:
#0 0x96fc52d4 in CFRetain
#1 0x96f94a54 in CFDictionarySetValue
#2 0x97029dd3 in -[CFXPreferencesSource setValue:forKey:]
#3 0x9702acce in __CFXPreferencesSetValuesInSource
#4 0x9702e30d in _CFXPreferencesRegisterDefaultValues
#5 0x92b90a98 in -[NSUserDefaults(NSUserDefaults) registerDefaults:]
#6 0x000ae543 in -[DataModelDefaults init] at DataModelDefaults.m:90
- (id) init {
self = [super init];
_defs = [NSUserDefaults standardUserDefaults];
NSArray* defaultGuides = [DataModelDefaults defaultGuideSettings];
NSDictionary* defs = [NSDictionary dictionaryWithObjectsAndKeys:
defaultGuides, kGuideSettings,
[NSNumber numberWithFloat:2], kEffectDefaultsDurationSeconds,
0];
// this goes BOOOOOM
[_defs registerDefaults:defs];
return self;
}
+ (NSArray *) defaultGuideSettings {
// simply return a list of the guide objects we want to have as
defaults
NSMutableArray* array = [[NSMutableArray new] autorelease];
[array addObject:[GuideSetting guideSettingNamed:@"Standard" width:
640 height:480]];
[array addObject:[GuideSetting guideSettingNamed:@"Standard" width:
800 height:600]];
[array addObject:[GuideSetting guideSettingNamed:@"YouTube" width:848
height:480]];
return array;
}
Am I forgetting something? I thought as long as my object could encode/
decode itself, all would be OK - anyone know what I'm doing wrong?
Thanks
--
John Clayton
Skype: johncclayton -
From the documentation:
...
A defaultâs value must be a property list, that is, an instance of (or
for collections a combination of instances of): NSData,NSString,
NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any
other type of object, you should typically archive it to create an
instance of NSData. For more details, see User Defaults Programming
Topics for Cocoa.
...
So, no, ensuring that a class conforms to <NSCoding> will not make
instances of said class compatible with NSUserDefaults.
b.bum


