Dre*_*ren 2 self ios objective-c-blocks
我发现构造__strong typeof(self)self = weakSelf。
它允许删除NSAssert宏自我捕获,但是我怀疑以这种方式使用它是否正确?
__weak typeof(self)weakSelf = self;
self.signupBlock = ^{
__strong typeof(self)self = weakSelf;
NSLog (@"%d", self.property)
NSAssert((self.property > 5), @"Some message");
}
Run Code Online (Sandbox Code Playgroud)
请咨询。
抱歉,我必须首先说使用__strong typeof(self)strongSelf = weakSelf;
当使用NSAssert宏时,构造结果导致出现警告,而我认为是内存循环,因为它包含self in。
self只是一个变量名,因此在本地重新定义它是完全可以的。甚至可能更喜欢
__strong typeof(weakSelf) strongSelf = weakSelf;
Run Code Online (Sandbox Code Playgroud)
因为
self并可能创建保留循环。此外,您可能希望查看此问题的答案,以讨论何时self在块中使用弱/强,而libextobjc库用于整洁@weakify/ @strongify宏。
| 归档时间: |
|
| 查看次数: |
231 次 |
| 最近记录: |