设置NSString变量循环

Jac*_*ień 0 variables objective-c

我在.h文件中声明了NSSTring变量

@property (nonatomic, retain) NSString *currencyCode;
Run Code Online (Sandbox Code Playgroud)

在我的.m文件中,我试图使用以下方法设置此变量:

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

程序循环开启 self.currencyCode = code;

currencyCode是零而code不是

这里发生了什么?

Mun*_*ndi 5

self.currencyCode = x;
Run Code Online (Sandbox Code Playgroud)

是...的同义词

[self setCurrencyCode:x];
Run Code Online (Sandbox Code Playgroud)

所以你在无限循环中调用setter.请改用:

_currencyCode = code; 
Run Code Online (Sandbox Code Playgroud)