value assigned to a property in the model class disappears in the view/controller class

隐身守侯 提交于 2019-12-02 13:16:06

I can guess that problem lies in the way you assign your stringForDisplay, eg.:

if you use something like

stringForDisplay_ = anotherString;

setter for property doesn't fire, so you have to retain your variable yourself otherwise it'll live just until your method finishes;

If so - use property setters, eg.:

self.stringForDisplay = anotherString;

that way ARC will do all the memory management.

Maybe I'm missing something but your property is declared in the class extension of CalculatorBrain so nobody outside CalculatorBrain.m knows about this property.

So if you want to expose this property to other objects, you will have to declare it in CalculatorBrain.h instead.

Oh - your declaration of the property whatHappenedSinceLastClear isn't exposed to other classes that import CalculatorBrain.h because you put the property declaration in an interface extension in the .m file, which other classes will not see.

To make it publicly accessible move the @property line for whatHappenedSinceLastClear to CalculatorBrain.h, not the .m file.

It really depends how you set stringForDisplay inside the performOperation:withArray: method.

for a blind guess, try using

NSString *otherString = self.brain.stringForDisplay;

after this line

double result = [self.brain performOperation:operation withArray:[self.brain whatHappenedSinceLastClear]];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!