Прямо перед тем, как мой класс модели отправляет переменную stringToDisplay
, NSLog показывает мне, что она имеет значение. Но когда я пытаюсь использовать его в своем ViewController, я просто получаю (null)
. Любые мысли о том, что я делаю неправильно?
(Хорошая новость заключается в том, что, работая над этим, я совершил своего рода прорыв в понимании того, как модели и контроллеры связаны друг с другом. Я все еще полный новичок, но я не чувствую себя таким потерянным, как раньше.)
Вот что я думаю, это соответствующий код:
CalculatorBrain.h
#import <Foundation/Foundation.h>
@interface CalculatorBrain : NSObject
@property (nonatomic) NSMutableString *stringToAdd;
@property (nonatomic,strong) NSString *stringForDisplay;
- (double)performOperation:(NSString *)operation withArray:(NSMutableArray *)particularStackYouNeedToPopOff;
КалькуляторBrain.m
@implementation CalculatorBrain
@synthesize stringToAdd = _stringToAdd;
@synthesize stringForDisplay = _stringForDisplay;
@synthesize whatHappenedSinceLastClear = _whatHappenedSinceLastClear;
- (double)performOperation:(NSString *)operation withArray:(NSMutableArray *)particularStackYouNeedToPopOff
{
<long code that I think doesn't matter because this NSLog produces exactly what I want it to:>
NSLog(@"%@",stringForDisplay);
return result;
}
CalculatorViewController.h
#import <UIKit/UIKit.h>
@interface CalculatorViewController : UIViewController
@property (nonatomic) NSArray *arrayOfDictionaries;
@property (nonatomic) NSDictionary *dictionary;
@property (weak, nonatomic) IBOutlet UILabel *variablesUsed;
@property (nonatomic, strong) NSString *operation;
@end
CalculatorViewController.m
#import "CalculatorViewController.h"
#import "CalculatorBrain.h"
@interface CalculatorViewController ()
@property (nonatomic,strong) CalculatorBrain *brain;
@end
@implementation CalculatorViewController
@synthesize display = _display;
@synthesize history = _history;
@synthesize brain = _brain;
@synthesize operation = _operation;
- (IBAction)operationPressed:(UIButton *)sender
{
NSString *otherString=[self.brain stringForDisplay];
if (self.userIsEnteringNumber) [self enterPressed];
NSString *operation = sender.currentTitle;
double result = [self.brain performOperation:operation withArray:[self.brain whatHappenedSinceLastClear]];
self.display.text = [NSString stringWithFormat:@"%g",result];
self.history.text = otherString;
NSLog(@"%@",otherString);
}
И NSLog в этой последней строке кода дает мне (null)
.
есть идеи?