views:

16

answers:

1

Hey everyone,

I am encountering an issue while posting a variable with Xcode:

While running this code the app crashes while posting the variable to a webservice:

NSArray *array = [stringFromFile componentsSeparatedByString: @","];
NSString *time = [array objectAtIndex:1];
UTCorLocal = time;
NSLog(@"%@", UTCorLocal);

UTCorLocal variable is declared earlier in the code. The NSLog outputs the correct string, but when I try to use it further along in the code it crashes.

When I give the variable a static value like this:

UTCorLocal = @"UTC";

It all runs like it should do!

Could anybody please help, it's driving me crazy!

Thanks a lot,

Ron

A: 

It's probably released somewhere along the way, I would guess, without knowing the rest of your code. Try copying or retaining 'time' and see what happens.

Joseph Tura
Thanks for your help, but what do you exactly mean by copying or retaining the variable? Do you mean I should alloc it or is there another way? Thanks!
Ron
It was a releasing problem I think. I changed the code to: UTCorLocal = [[NSString alloc] initWithFormat:@"%@",time]; And now everything works fine!
Ron