나는 생각할 수있는 모든 것을 시도했으며,이 오류를 수정하기위한 모든 제안을 시도했다. 앱이 iOS 시뮬레이터에서 제대로 실행되지만 실제 기기 (내 iPhone 5)에서 충돌합니다. 이 클래스의 특성변하기 쉬운 메소드가 물리적 객체에서만 발생하는 불변 객체로 전송 됨
2015-01-23 16:26:43.232 Kyle's App[2343:773183] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'
선언은 다음과 같습니다 :
@property (strong, nonatomic) NSUserDefaults *defaults;
@property (strong, nonatomic) NSMutableArray *classes;
@property (strong, nonatomic) NSMutableArray *foundClasses;
이 모든
가 변경 가능한 객체로 초기화 사용자 기본값 을 제외하고 여기에 는 오류가 내가 얻을 수있다 오류가 발생하는 방법 :- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableArray *notes = [[NSMutableArray alloc] initWithArray:self.classes[indexPath.row][@"notes"]];
[notes addObject:[[self.defaults objectForKey:@"New Note"] mutableCopy]];
self.classes[indexPath.row][@"notes"] = [notes mutableCopy];//problem
[self.defaults setObject:@(indexPath.row) forKey:@"Current Class"];
[self.defaults setObject:self.classes forKey:@"Classes"];
[self.defaults setObject:[self.defaults objectForKey:@"New Note"] forKey:@"Current Note"];
[self.defaults setObject:@YES forKey:@"Created New Note"];
[self.defaults synchronize];
[self performSegueWithIdentifier:@"Show Summary" sender:self];
}
오류가 발생하는 경우 self.classes[indexPath.row][@"notes"] = [notes mutableCopy];//problem
모든 도움을 주셔서 감사 드리며, 잘못된 것이 있으면 사과드립니다. 처음 StackOverflow에 게시하는 것이므로 잘못되었습니다. 더 자세한 정보가 필요하면 알려주십시오.
감사합니다.
업데이트 - 사전에 초기화 된 코드가 있는데 어떻게 여전히 불변인지 알 수 없습니다.
[self.classes addObject:(NSMutableDictionary *)@{
@"title": textField.text,
@"notes": [[NSMutableArray alloc] init]//(NSMutableArray *)@[]
}];
여기서 'self.classes'에 사전을 입력하는 코드는 어디에 있습니까? 'NSDictionary'가 아닌'NSMutableDictionary'을 추가 할 필요가 있습니다. – rmaddy
'노트'배열이 변경 가능한 배열이므로 'mutableCopy'메서드가 불필요합니다 – stosha
이것을보십시오'self.classes [indexPath.row] [@ "notes"] = [노트 사본]; – Saif