I'm using a NSDictionary
to get a NSString
from a plist with the following code:
NSString *fullPath = [[NSBundle mainBundle] pathForResource:@"TestIds" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary dictionaryWithContentsOfFile:fullPath] retain];
NSString *testid = [dictionary objectForKey:@"testId"];
and then I save it in a NSMutableArray
with objects of a class I created:
// 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];
the application does some stuff with other things and then calls a method which calls the NSString
:
IdDescription *desc = [array objectAtIndex:n];
NSLog(@"%@", desc.testId); // testId is a property with retain
The problems is that the application crashes or gets interrupted and all kind of things when it gets to the NSLog
line. The most rare thing is that it works if I change the line:
NSString *testid = [dictionary objectForKey:@"testId"];
for:
NSString *testid = @"testId_1"; // or any other string
I tested adding:
if ([testid compare:@"testId_1"] == NSOrderedSame)
testid = @"testId_1";
after the
NSString *testid = [dictionary objectForKey:@"testId"]
and it still works.
I also tried using
NSString *testid = [NSString stringWithFormat:@"testId_%d", 1]
instead of the troubling line but it crashes with the same EXC_BAD_ACCESS
error.
Anybody knows what could be the problem? I have tried almost everything. Any help is most appreciated.