我使用的是NSDictionary
从与下面的代码的plist得到了NSString
iPhone应用:的NSString问题的
NSString *fullPath = [[NSBundle mainBundle] pathForResource:@"TestIds" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary dictionaryWithContentsOfFile:fullPath] retain];
NSString *testid = [dictionary objectForKey:@"testId"];
,然后我把它保存在一个NSMutableArray
与我创建了一个类的对象:
// before the code above
NSMutableArray *array = [[NSMutableArray array] retain]; // this is actually a global variable
// after the code
IdDescription *idDesc = [[IdDescription alloc] initWithId:testid];
[array addObject:idDesc];
应用做一些东西,其他的事情,然后调用它调用NSString
的方法:
IdDescription *desc = [array objectAtIndex:n];
NSLog(@"%@", desc.testId); // testId is a property with retain
问题是应用程序崩溃或被中断以及所有类型的事情,当它到达NSLog
行。最难得的是,它的工作原理,如果我改变行:
NSString *testid = [dictionary objectForKey:@"testId"];
为:
NSString *testid = @"testId_1"; // or any other string
我测试加:
if ([testid compare:@"testId_1"] == NSOrderedSame)
testid = @"testId_1";
后
NSString *testid = [dictionary objectForKey:@"testId"]
它仍然有效。
我也使用
NSString *testid = [NSString stringWithFormat:@"testId_%d", 1]
,而不是麻烦的线尝试,但它与同EXC_BAD_ACCESS
错误崩溃。
任何人都知道可能是什么问题?我尝试了几乎所有的东西。任何帮助最受赞赏。
供参考:如果您缩进代码四个空格,它将显示在等宽字体和语法突出显示,所以它更容易阅读:) – 2010-09-30 05:52:17
请格式化您的代码,使其更具可读性。有关指导,请参阅[Markdown编辑帮助](http://stackoverflow.com/editing-help)。 – 2010-09-30 05:53:49
如果您在NSString * testid = [dictionary objectForKey:@“testId”]后执行NSLog(@“%@”,testid),它会崩溃吗?线?调试器和控制台在崩溃后显示什么? – Altealice 2010-09-30 06:21:58