Reputation: 241
I have an array that has different data, one being temperature recorded in celcius. when a user changes the default setting to fahrenheit i need to change the array of information when it displays in a collectionView. the program compiles properly, but when the view loads the compiler crashes with no error and just highlights the line in green and say in right corner Thread 1: breakpoint1.1
The line highlighted is bellow
[dict setObject:[NSNumber numberWithInteger:number] forKey:@"temp"];
i have also just tried with no success just to bypass the problem:
[dict setObject:@"11" forKey:@"temp"];
my code for looping through the array and changing the data is:
changedArray = [[NSMutableArray alloc] initWithCapacity:50];
for (NSMutableDictionary *dict in locationArray) {
if ( [[dict objectForKey:@"site"] isEqual:[defaults objectForKey:@"location"]] ) {
NSInteger number = [[dict objectForKey:@"temp"] integerValue];
number = ((number * 1.8) + 32);
[dict setObject:[NSNumber numberWithInteger:number] forKey:@"temp"];
[changedArray addObject:dict];
}
}
If i remove the three lines of code changing the temperature value in the dict, it compiles and run correctly. Any inside for this ios noob would be great thanks. :-)
Upvotes: 1
Views: 1455
Reputation: 10201
I guess the dictionary instances in your array are all immutable NSDictionary
object. Just type casting won't turn them to mutable ones. Try the following
NSMutableDictionary
But my advice would be to keep the temperate in only one unit always, the unit which the users tend to use more. Only when you need to display it, check with the user chosen unit do the calculation and refresh it.
Upvotes: 2