And--- as usual, moments after asking a question, something occurs to me that makes me identify the cause of the odd behavior, except I still don't quite understand it.. but at least I was able to fix it.
The problem was, I was also subclassing. I had accidentally redefined the same propery in the subclass... Though I wasn't overwriting the getter/setter: @interface FancyList : List @property (nonatomic, weak) Cell *currentCell; @end @implementation @end And this for some reason caused the base classes ivar to never get set? Somehow it got confused and wasn't able to access the real ivar? or something? Anyway.. deleting that property in the subclass fixes the issue. Patrick J. Collins http://collinatorstudios.com On Sat, 8 Oct 2016, Patrick J. Collins wrote: > Every once in a while, I experience behavior that really throws me off > and makes me realize I do not fully understand ARC. I just came across > one of these situations. > > I have some code that does something like: > > @interface List () > @property (nonatomic, strong) NSArray *cells; > @property (nonatomic, weak) Cell *currentCell; > @end > > @implementation List > > -(instancetype)init { > if (self = [super init]) { > [self createCells]; > } > return self; > } > > -(void)createCells { > NSMutableArray *cells = [NSMutableArray array]; > for (int i = 0; i < 10; i++) { > [cells addObject:[[Cell alloc] init]]; > } > self.cells = [cells copy]; > } > > -(void)didTapCell:(Cell *)cell { > if (self.currentCell != cell) { > self.currentCell = cell > } > } > > @end > > The problem is, when didTapCell: is called, the self.currentCell != cell > check is always true, because self.currentCell is always nil-- which I > do not understand at all because it's being stored in an NSArray, which > to my knowledge means it's a strong reference. > > I can inspect self.cells and the cells are there, so why do I need to > make currentCell a strong property in this case? > > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Objc-language mailing list ([email protected]) > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/objc-language/patrick%40collinatorstudios.com > > This email sent to [email protected] _______________________________________________ Do not post admin requests to the list. They will be ignored. Objc-language mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/objc-language/archive%40mail-archive.com This email sent to [email protected]
