2011-08-31 2 views
-1

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"];

답변

1

(엑스 코드는 대소 문자를 구별한다는 점을 기억하십시오!)가 (아마도)에 NSDictionary라는 키 @"Name" 아무 객체가 없기 때문에 대부분의 경우입니다 temp.

더 구체적인 답변을 보려면 temp을 정의하는 코드를 게시해야합니다.

+0

내 문제를 명확히하기 위해 내 질문을 편집했습니다. – bubbles