When running the below code, the [dict setValue:@"null" forKey:@"name"];
keeps crashing. I search on here and found other posts were caused by people not using NSMutableDictionary
. However I am using this.
Why is it crashing on this line if name
is null
?
NSMutableArray *tempCustomers = [[NSMutableArray alloc] init];
for (NSMutableDictionary *dict in [[json objectForKey:@"data"] mutableCopy]) {
if ([dict objectForKey:@"name"] == [NSNull null]) {
[dict setValue:@"null" forKey:@"name"];
}
[tempCustomers addObject:dict];
}
I ended up using this. I'm guessing this is what a deepMutableCopy is?
NSMutableArray *tempCustomers = [[NSMutableArray alloc] init];
for (NSMutableDictionary *dict in [[json objectForKey:@"data"] mutableCopy]) {
if ([dict objectForKey:@"name"] == [NSNull null]) {
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
tempDict = [dict mutableCopy];
[tempDict setValue:@"null" forKey:@"name"];
[tempCustomers addObject:tempDict];
} else {
[tempCustomers addObject:dict];
}
}
maybe mutableCopy is not "deepMutableCopy", i mean, you just enumerate mutable object but objects in this collection are not mutable (copy from my comment)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With