그래서 plist 파일을 사용하여 NSMutableArray를 저장하고 객체를 추가하면 해당 plist 파일에 저장됩니다.NSMutableArray에서 plist를 사용하는 동안 오류가 발생했습니다.
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
코드 :
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:1];
_prsPath = [documentsDirectory stringByAppendingPathComponent:@"records.plist"];
prs = [[NSMutableArray alloc] initWithContentsOfFile:_prsPath];
if (prs == nil) {
prs = [NSMutableArray array];
}
와 "addObject"후
:[prs writeToFile:_prsPath atomically:YES];
시간이 코드 Struggeling 그러나 나는이 오류를 얻고있다.
미리 감사드립니다.
먼저 요소에 액세스하려고 시도하기 전에 경로가 nil인지 확인하십시오. 그런 다음 요소에 액세스하려고 할 때 배열에 충분한 요소 (0보다 큼)가 있는지 확인하십시오. 사실, 그 배열이 nil이더라도 0을 반환 할 것이므로 1 단계를 건너 뛸 수 있습니다. – Till