Why is NSUserDefaults saying I'm adding a non-property-list object? It's just an NSArray with an NSDictionary, NSNumber and NSData [duplicate]

StackOverflow https://stackoverflow.com/questions/22718205

Domanda

NSUserDefaults docs:

A default object 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.

My code:

        NSData *provisionData = [NSData dataWithBytes:&provisionStruct length:sizeof(provisionStruct)];
        NSDictionary *accountIndexToProvisionPairing = @{@(globalSelf.accountIndexBeingSetup): provisionData};

        NSMutableArray *newProvisionedDevices = [[[NSUserDefaults standardUserDefaults] objectForKey:@"ProvisionedDevices"] mutableCopy];
        [newProvisionedDevices addObject:accountIndexToProvisionPairing];

        [[NSUserDefaults standardUserDefaults] setObject:newProvisionedDevices forKey:@"ProvisionedDevices"];

Yet I get this every time I run it:

Attempt to set a non-property-list object ( { 0 = <8b48ea2d b326da4b 82311275 d7f81960 6f481b01 b4d5146e 5bfc58e3 3d85e98d>; }

What am I doing that involves a non-property-list object? It's just an NSArray of NSDictionaries, holding an NSNumber and NSData. All valid according to the above paragraph.

È stato utile?

Soluzione

NSUserDafults restrictions applies not only to values but also to keys. It seems that your globalSelf.accountIndexBeingSetup is an integer number so @(globalSelf.accountIndexBeingSetup) is a NSNumber. Try to use [@(globalSelf.accountIndexBeingSetup) description] as a key to check this guess.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top