Last active
July 15, 2020 06:42
-
-
Save FrizzleFur/7fd8a45d651887bb866722b4e5563f8f to your computer and use it in GitHub Desktop.
Block循环引用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ```objc | |
| typedef void(^blk_t)(void); | |
| @interface Person : NSObject | |
| { | |
| blk_t blk_; | |
| } | |
| @property (nonatomic, weak) NSArray *array; | |
| @end | |
| @implementation Person | |
| - (instancetype)init | |
| { | |
| self = [super init]; | |
| blk_ = ^{ | |
| NSLog(@"array = %@",_array);//循环引用的警告提示 | |
| }; | |
| return self; | |
| } | |
| ``` | |
| /* | |
| 还是会有循环引用的警告提示,因为循环引用的是self和block之间的事情, | |
| 这个被Block持有的成员变量是strong还是weak都没有关系, | |
| 而且即使是基本类型(assign)也是一样。 | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment