NSDictionary to iCloud iOS and NSDictionary to JSON
Well the other day i've treated save NSDictionary to iCloud but only execute the command.
//code for save NSDictionary to iCloud value: NSDictionary key:NSString
[[NSUbiquitousKeyValueStore defaultStore] setDictionary:value forKey:key];
it doesn't save. So after many times i found the solution...
Well if you use the next code with your NSDictionary. You can test before submit to iCloud. if return error you won't save a NSDictonary to iCloud unless you fix it.
+ (NSString*) dictionaryToJSON:(NSDictionary*)dictionary{
NSString *JSON;
NSError *error;
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:&error];
if (error) {
NSLog(@"dictionaryToJSON error: %@", error);
return JSON;
}
JSON =[[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding];
return JSON;
}
Thank You... See you later...!
Written by Raul Silva
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#