i want to save NSInteger to iCloud when the view controller is loaded. I've tried save NSInteger data to iCloud, but i fail to do so. I therefore convert it to NSNumber instead. So the problem is when i try to save the NSNumber to iCloud, it fails with an error
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key coins cloud.'
here is the code i used
NSInteger currentValue = [[NSUserDefaults standardUserDefaults]
integerForKey:@"coins.demo"];
NSNumber *currentvalue = [NSNumber numberWithInt:currentValue];
NSUbiquitousKeyValueStore *cloudStore = [NSUbiquitousKeyValueStore defaultStore];
[cloudStore setValue:currentvalue forKey:@"coinscloud"];
[cloudStore synchronize];
NSNumber *cloudcoins = [cloudStore valueForKey:@"coinscloud"];
_coinLabel.text = [NSString stringWithFormat:@"%li", (long)]coinscloud];
I will appreciate your help
Use
-setObject:forKey:
(NSUbiquitousKeyValueStore
) instead:BTW:
Are you really sure that you want to use a key, not key path of
coins.demo
?