Hello,
I am having a... strange problem.
I am adding an NSDictionary to an NSArray, then saving it to the defaults. When I check the object count of that key on the user defaults, it says the count is 0, but the array that's "on memory" has that object (so the count is 1).
The code, along with the output it gives is this:
(array is an NSArray, defaults is [NSUserDefaults standardUserDefaults])
- (void)addSongToQueue:(NSDictionary *)songData {
[array addObject:songData];
[defaults setObject:array forKey:@"OfflineArray"];
[defaults synchronize];
#if DEBUG
NSLog(@"Dictionary Data Received: %@", songData);
NSLog(@"Object Count on Array: %u", [array count]);
NSLog(@"Object Count on Defaults: %u", [[NSArray arrayWithArray:[defaults objectForKey:@"OfflineArray"]] count]);
[defaults removeObjectForKey:@"OfflineArray"];
[defaults synchronize];
#endif
}
This is how I am calling it:
[className addSongToQueue:[NSDictionary dictionaryWithObjectsAndKeys:@"yadda", @"yadda", nil]];
This is the output: (I ran it twice, just to make sure :P)
2010-10-11 21:47:35.807 AppName[1119:207] Dictionary Data Received: {
yadda = yadda;
}
2010-10-11 21:47:35.807 AppName[1119:207] Object Count on Array: 1
2010-10-11 21:47:35.808 AppName[1119:207] Object Count on Defaults: 0
2010-10-11 21:47:36.647 AppName[1119:207] Dictionary Data Received: {
yadda = yadda;
}
2010-10-11 21:47:36.647 AppName[1119:207] Object Count on Array: 2
2010-10-11 21:47:36.648 AppName[1119:207] Object Count on Defaults: 0
So yeah. I can't be able to solve it. :/
Thanks in advance. :)