我目前正在为plist.in这个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?
}
我把数据转化为变量的原因是因为后者我将使用这些值来测试对检查我想对我的分贝执行..确保事情像我收到正确的请求数等
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 2012-04-04 01:59:44
我已经更新了我的plist的屏幕截图,如上所示,您可以看到我正在试图弄清楚如何编码缓存值字典及其子值 – 2012-04-04 02:05:30