Right before my model class sends the variable stringToDisplay
, NSLog shows me that it has a value. But when I try to use it in my ViewController, I just get
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.
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]];
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.
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.