약간의 문제가 발생했습니다. 나는 다음 데이터를 포함하는 .plist 파일을 가지고있다. .plist 파일에서 읽기
그래서 나는 배열 읽기보다 첫 번째 배열을 읽어야한다. 아니면 파일을 재 작성하고 사전을 입력 루트 키를 변경하고, 다음과 같이 읽을 필요 :
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSString *plistPath;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
plistPath = [rootPath stringByAppendingPathComponent:@"Data.plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
}
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
if (!temp) {
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
self.personName = [temp objectForKey:@"Name"];
self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
이 존재하는 경우 폴더를 문서에서 파일을로드하는 코드를 던진다. – rmaddy
그리고 실제로 질문에 대답하지 않습니다. 질문은 배열에서 원하는 데이터를 가져 오는 것입니다. – rmaddy
'objectAtIndex :'는 오래된 구문입니다. 새로운 것입니다. –