plist - NSMutableDictionary - 0x0

时间:2012-03-23 14:08:01

标签: dictionary plist mutable

我遇到了问题:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
    NSString *settingPath = [[[NSString alloc] init] autorelease];
    settingPath = [[NSBundle bundleWithPath:filePath] pathForResource:@"Root" ofType:@"plist"];
    NSMutableDictionary *plist = [[[NSMutableDictionary alloc] init] autorelease];
    plist = [NSMutableDictionary dictionaryWithContentsOfFile:settingPath];

在这个plist为零之后,地址为0x0 ......但为什么呢? 任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

下面是一些应该可行的代码:

NSString* path = [[NSBundle mainBundle] pathForResource:@"myfile" ofType:@"plist"];
NSDictionary* dictionary = [NSDictionary dictionaryWithContentsOfFile:path];

请注意,plist必须有效,否则您将获得空值。

另外,请注意,如果您要在另一个调用中覆盖其值,则不需要使用alloc / init来创建变量。