The code is an example. I don’t know if my understanding is correct.
[self.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.otherView.mas_centerY);
}];
The block holds self, but self.view does not hold this block, because the source code of Masonry is as follows:
- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block {
self.translatesAutoresizingMaskIntoConstraints = NO;
MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
block(constraintMaker);
return [constraintMaker install];
}
It is just block(constrainMaker). If it is changed to self.block = block(constrainMaker), does the view also hold the block?
It is not true that block will definitely cause a circular reference. Whether it is a circular reference depends on whether they hold strong references to each other. If self is used in a block, the block will keep a reference to self, but self does not hold the block directly or indirectly, so it will not cause a circular reference.
Your understanding is correct.