[self.someView doSomething:^{
self.aVar = @"Hello!";
}];
I will do:
__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello!";
}];
But if I call a method on weakSelf, and the method uses self, even if I don’t get a warning, will this cause a retention period? I’m talking about this:
__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello! ";
[weakSelf aMethod];
}];
Use self with aMethod
Using objects in the block will implicitly increase the retention count. But you have to Call a method on weakSelf instead of self, so the reserved count is not affected.
When I call myself in a block reserved by myself, I usually receive To the warning:
[self.someView doSomething:^{
self.aVar = @"Hello!";
}];< /pre>I will do:
__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello!";
}];But if I call a method on weakSelf, and the method uses self, even if I don’t get a warning, will this cause a retention cycle? ? I'm talking about this:
__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello! ";
[weakSelf aMethod];
}];Use self with aMethod
As long as your weakSelf is declared outside your block, there is no retention period.
Using objects in the block will implicitly increase the retention count. But you have to call a method on weakSelf instead of self, so the retention count Not affected.