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/archive%40mail-archive.com
This email sent to [email protected]