현재이 plist에 대한 컨트롤러 클래스를 만들고 있습니다.이 plist에는 여러 가지 유형이있는 루트 사전이 있습니다 (숫자, 문자열 및 사전). 내 컨트롤러 클래스에서 plist를 확인한 다음 문서에 추가하여 읽고 읽고 쓸 수 있습니다.사전에 속성 목록의 사전에 값을 추가하는 방법
여기에서 필자는 현재 plist에서 whats를 읽고이 값들을이 클래스에서 설정 한 tempvars로 전달합니다.
내 읽기 방법은 내 plist 컨트롤러 클래스에서와 같습니다.
-(void) readPlistData
{
// Data.plist code
// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"EngineProperties.plist"];
// 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:@"EngineProperties" 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);
}
// assign values
self.protocolSignature = [temp objectForKey:@"Protocol"];
self.requestNumber = [temp objectForKey:@"RequestNumber"];
//How do I add the dictionary values here?
}
내가 변수에 데이터를 넣어 이유 때문에 나는 올바른 요청 번호를 수신하고 같은 것들을 확인하고 .. 내 DB에 대해 수행 할 검사에 대해 테스트 할이 값을 사용하기 위하여려고하고 후자
UPDATE : 내 생각에 루트 사전에 사전에 추가하면됩니다. 나는 가까이에 있지 않다고 생각하지만, 내가하는 일에 대해 당신에게 더 나은 단서를 줄 수 있습니다.
self.cacheValue = [temp objectForKey:@"Cache Value"];
self.manufacturers = [cacheValue objectForKey:@"Manufacturers"];
self.models = [cacheValue objectForKey:@"Model"];
self.subModels = [cacheValue objectForKey:@"SubModels"];
어떤 도움을 주시면 대단히 감사하겠습니다.
plist의 기본 예제를 제공 할 수 있습니까? 나는 당신의 모범에서 그것을 따르는 것이 아닙니다. NSMutableDictionary를 사용하려는 것 같습니다. – rwyland
캐시 값 사전과 해당 하위 값을 코딩하는 방법을 알아 내려고 위와 같이 위와 같이 내 plist 스크린 샷을 업데이트했습니다. –