I’m trying to do lazy instantiation for my arrayWithCurrentLadder property so that my array gets allocated and initiated at least once. However, it seems that my setter never actually gets called, because when I try to do stuff with the objects in the array nothing happens, and so I decided to try and NSLog an object in the array to find out if I was getting an actual value (I put stars by that line of code so you can see) and the debugger said (null), so I’m assuming my setter isn’t actually setting. I added random NSLogs in my setter to see again but the messages didn’t even show up in the debugger. Why won’t my setter set?
#import "LViewController.h"
@interface LViewController ()
@property (nonatomic) BOOL firstLadder;
@property (nonatomic, weak) NSMutableArray *arrayWithCurrentLadder;
@property (weak, nonatomic) IBOutlet UIView *playingView;//connects playingView to LViewController
@end
@implementation LViewController
@synthesize playingView = _playingView;
@synthesize firstLadder = _firstLadder;
@synthesize arrayWithCurrentLadder = _arrayWithCurrentLadder;
-(void)setArrayWithCurrentLadder:(NSMutableArray *)arrayWithCurrentLadder {
if(!_arrayWithCurrentLadder)
_arrayWithCurrentLadder = [NSMutableArray arrayWithCapacity:10];
NSLog(@"kgjfkjg");
_arrayWithCurrentLadder = arrayWithCurrentLadder;
NSLog(@"dkfjdk");
}
- (IBAction)buildLadder:(UIButton *)sender {
if (self.firstLadder) {
*******************************************************************************************
NSLog(@"%@", [[self.arrayWithCurrentLadder lastObject] frame].origin.x);
*******************************************************************************************
if (sender.frame.origin.x == [[self.arrayWithCurrentLadder lastObject] frame].origin.x) {
sender.backgroundColor = [UIColor redColor];
[self.arrayWithCurrentLadder addObject:sender];
}
}
}
- (IBAction)startingLadder:(UIButton *)sender {
if (!self.firstLadder) {
[self.arrayWithCurrentLadder addObject:sender];
}
sender.backgroundColor = [UIColor redColor];
self.firstLadder = YES;
}
@end
You should override the getter instead of the setter: