I have a string in my header file named
NSString *enemy;
In implementation file i'm initializing that string from a plist file like this
NSString *path = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
NSDictionary *data = [NSDictionary dictionaryWithContentsOfFile:path];
NSDictionary *level_data = [data objectForKey:[@"Level" stringByAppendingFormat:@"%d", level]];
enemy = [level_data objectForKey:@"enemy"];
and then this "enemy" string, when i use it in method like this
-(void) addEnemy{
if([enemy isEqualToString:@"Ostrich"]){
[some_Obj valueCalc:t];
}
}
it works fine for the first call to that "addEnemy" method but when i call this method again the string "enemy" throws an Exception. After debugging i came to know that at second call to the method "addEnemy" the string "enemy" shows "Variable is not NSString" in debugger.
but if i initialize "enemy" like this
enemy = [[NSString alloc] initWithString:[level_data objectForKey:@"enemy"]];
then it works quite fine.
Can anyone tell me why the above mentioned problem occurs?