我在存储和访问 NSUserDefault 中的多维数组时遇到了一些麻烦。任何帮助,将不胜感激。运行此代码时出现的错误是“ *由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因:'-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'”
//To create, add values to and store arrays
multiArray = [[NSArray alloc] init];
multiArray = [NSArray arrayWithObjects:[NSMutableArray array], [NSMutableArray array], [NSMutableArray array], nil];
[[multiArray objectAtIndex:0] addObject:[NSNumber numberWithDouble:number1]];
[[multiArray objectAtIndex:1] addObject:[NSNumber numberWithDouble:number2]];
[[multiArray objectAtIndex:2] addObject:[NSNumber numberWithDouble:number3]];
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults]
[standardUserDefaults setObject:multiArray forKey:@"multiArray"];
[standardUserDefaults synchronize];
//To access the array
NSArray *multiArrayCopy = [[NSArray alloc] init];
multiArrayCopy = [[standardUserDefaults objectForKey:@"multiArray"] mutableCopy];
NSLog(@"array count is %i", [[multiArrayCopy objectAtIndex:2] count]);
Label1.text = [NSString stringWithFormat:@"%@", [[multiArrayCopy objectAtIndex:0] objectAtIndex:0]];
Label2.text = [NSString stringWithFormat:@"%@", [[multiArrayCopy objectAtIndex:1] objectAtIndex:0]];
Label3.text = [NSString stringWithFormat:@"%@", [[multiArrayCopy objectAtIndex:2] objectAtIndex:0]];