Jacek Kwiecień
Jacek Kwiecień

Reputation: 12659

Seting NSString variable loops

I have NSSTring variable declared in my .h file

@property (nonatomic, retain) NSString *currencyCode;

In my .m file I'm trying to set this variable using following method:

-(void)setCurrencyCode:(NSString *)code {
    self.currencyCode = code;
    [currencyButton setTitle:currencyCode forState:UIControlStateNormal];
}

Program loops on self.currencyCode = code;

currencyCode is nil and code isn't

What is happening here?

Upvotes: 0

Views: 56

Answers (2)

uchuugaka
uchuugaka

Reputation: 12782

You don't need to implement this. Synthesize it. Set the UI label in an IBAction method or another method.

Upvotes: 0

Mundi
Mundi

Reputation: 80271

self.currencyCode = x;

is a synonym for

[self setCurrencyCode:x];

So you are calling the setter in an infinite loop. Use this instead:

_currencyCode = code; 

Upvotes: 5

Related Questions