示例代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
// - weak & strong #define myWeakify(VAR) \ try {} @finally {} \ __weak __typeof__(VAR) VAR##_myWeak_ = (VAR) #define myStrongify(VAR) \ try {} @finally {} \ __strong __typeof__(VAR) VAR = VAR##_myWeak_ #define myStrongifyRetVIfNil(VAR, RET) \ try {} @finally {} \ __strong __typeof__(VAR) VAR = VAR##_myWeak_;\ if (VAR == nil) return RET #define myStrongifyRetNIfNil(VAR) \ try {} @finally {} \ __strong __typeof__(VAR) VAR = VAR##_myWeak_;\ if (VAR == nil) return |
使用如下:
1
2
3
4
5
6
7
8
9
|
- ( void )handleFromVC { NSArray *viewControllers = self.navigationController.viewControllers; @myWeakify(self); [viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { @myStrongifyRetNIfNil(self); //代码 }]; } |
如有疑问请留言或到本站社区交流讨论,感谢阅读,希望通过本文能帮助到大家,谢谢大家对本站的支持!
原文链接:http://blog.csdn.net/robinson_911/article/details/73471384