NSMutableDictionary *firstCurr;
NSLog(@"currency list count=%d",[self.currencyList count]);
for (int j=0; j<[self.currencyList count]; j++)
{
NSLog(@"j=%d",j);
firstCurr = [self.currencyList objectAtIndex:j];
[firstCurr setValue:[NSNumber numberWithFloat: [[currencyItems objectAtIndex:j]floatValue]] forKey:kSelectedCurrencyINR];
}
通貨リストと呼ばれる nsmutabledictionary オブジェクトの配列があり、nsmutabledictionary の 1 つのフィールドを設定しようとしています。マークされた行の firstCurr にアクセスすると、クラッシュが発生します!
NSMutableArray *arr;
arr = [[[NSMutableArray alloc] init] autorelease];
[[NSUserDefaults standardUserDefaults] setObject:arr forKey:kSelectedCurrencies];
これが配列に追加する方法です
NSDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease];
[dict setValue:countryCode[pos] forKey:kSelectedCurrencyCode];
[dict setValue:countryName[pos] forKey:kSelectedCurrencyCountry];
[dict setValue:[NSNumber numberWithFloat:2.0] forKey:kSelectedCurrencyINR];
[dict setValue:currencyName[pos] forKey:kSelectedCurrencyName];
[temp addObject:dict];
[[NSUserDefaults standardUserDefaults] setObject:temp forKey:kSelectedCurrencies];
[[NSUserDefaults standardUserDefaults] synchronize];