Я получаю данные JSON и сохраняю их в `NSUserDefaults ', которые затем пытаюсь получить, чтобы добавить или удалить объекты из словаря, однако я получаю ошибку
нераспознанный селектор, отправленный на экземпляр
при добавлении к NSMutableDictionary
// new dict
NSMutableDictionary *userTranslations = [NSMutableDictionary new];
for (NSString *key in keys) {
[userTranslations setObject:dicky[key] forKey:key];
};
// then add that dictionary as the key for uid
[artworkTranslations setObject:userTranslations forKey:uid];
Данные JSON
{
people = {
"title" = "Hello";
"details" = "Amet justo donec enim diam vulputate.<br><br>Ut etiam sit amet nisl. Mattis vulputate enim nulla aliquet porttitor.<br><br>Euismod quis viverra nibh cras pulvinar mattis nunc sed blandit. Dis parturient montes nascetur ridiculus mus.";
};
}
NSUserDefaults
Objects: {
9ddfdd2d652c742 = {
first = {
"title" = "Hello";
"details" = "Amet justo donec enim diam vulputate.<br><br>Ut etiam sit amet nisl. Mattis vulputate enim nulla aliquet porttitor.<br><br>Euismod quis viverra nibh cras pulvinar mattis nunc sed blandit. Dis parturient montes nascetur ridiculus mus.";
};
};
}
Полный код
NSDictionary * jsonData = [data objectForKey:@"people"];
if (jsonData) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *objects = [defaults objectForKey:@"Objects"];
NSArray *keys = [jsonData allKeys];
if (objects) {
// get people from UD
NSMutableDictionary *people = [objects objectForKey:uid];
if (people) {
NSLog(@"there ARE in people in dictionary from UD");
//get uid of person key and if exists then remove
[objects removeObjectForKey:uid]; // error here
// new dict
NSMutableDictionary *user = [NSMutableDictionary new];
for (NSString *key in keys) {
[users setObject:jsonData[key] forKey:key]; // Crash Here
};
// then add that dictionary as the key for uid
[people setObject:user forKey:uid];
} else {
NSLog(@"NO people dictionary in objects from UD");
NSMutableDictionary *users = [NSMutableDictionary new];
NSMutableDictionary *people = [NSMutableDictionary new];
for (id key in keys) {
NSMutableDictionary *person = [jsonData objectForKey:key];
[people setObject:person forKey:key]; // Crash here
};
[user setObject:people forKey:uid];
[objects setObject:users forKey:uid];
[defaults setObject:objects forKey:@"Objects"];
}
[defaults synchronize];
} else if (!objects){
NSLog(@"People NOT FOUND in UserDefaults");
NSMutableDictionary *people = [NSMutableDictionary new];
NSMutableDictionary *user = [NSMutableDictionary new];
for (NSString *key in keys) {
[users setObject:jsonData[key] forKey:key];
};
[people setObject:user forKey:uid];
[defaults setObject:people forKey:@"Objects"];
[defaults synchronize];
}
}