現在、plist のコントローラー クラスを作成しています。この plist には、いくつかの型 (Number、String、Dictionary) を持つルート ディクショナリがあります。コントローラー クラスでは、plist をチェックしてからドキュメントに追加するので、読み書きできます。
ここから、現在の plist の内容を読み取り、それらの値をこのクラスで設定した tempvars に渡します。
これは、plist コントローラー クラスでの read メソッドの外観です。
-(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?
}
データを変数に入れる理由は、後でこれらの値を使用して、データベースに対して実行したいチェックに対してテストするためです..正しいリクエスト番号を受け取っているなどのことを確認します.
更新::ルート辞書内の辞書にそれらを追加するという私の考えは、このようなものになります。私がやろうとしていることへのより良い手がかりを与えるかもしれません。
self.cacheValue = [temp objectForKey:@"Cache Value"];
self.manufacturers = [cacheValue objectForKey:@"Manufacturers"];
self.models = [cacheValue objectForKey:@"Model"];
self.subModels = [cacheValue objectForKey:@"SubModels"];
どんな助けでも大歓迎です。