plist에서 읽는 방법에 대해서는 Tutorial을 따라 왔습니다. 그러나 나는 키 이름으로 문자열을 읽을 수 없습니다. 나는 NSLog("%@", [temp objectForKey:@"Name"]);
을 넣어 봤지만 null을 반환합니다. 나는 xml 파일을 열고 수동으로 dict를 배열로 변경하는 것과 관련된 비슷한 문제가있었습니다. 이 문제를 어떻게 해결할 수 있습니까?xcode 4.0.2에서 plists 읽기 및 쓰기 - 사전에서 검색하는 문제
xml 파일의 계층 구조가 나를 혼란스럽게합니다. John Doe라는 문자열로 명명 된 루트를 만든 사전은 사전 자체의 일부입니까? 명확성이 인정되었습니다! 튜토리얼에서
은 위의 링크 :
// check to see if Data.plist exists in documents
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
{
// if not in documents, get property list from main bundle
plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
}
// read property list into memory as an NSData object
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSString *errorDesc = nil;
NSPropertyListFormat format;
// convert static property liost into dictionary object
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
if (!temp)
{
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
NSLog(@"%@", [temp objectForKey:@"Name"];
내 문제를 명확히하기 위해 내 질문을 편집했습니다. – bubbles