Files
knowledge-kit/Chapter1 - iOS/1.89.md
杭城小刘 e89fe0ca1c docs: 内容
2020-11-08 15:51:47 +08:00

21 lines
571 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# block 原理
1. 解决循环引用不应该使用 weakself而是使用 strong-weak
```Objective-c
__weak typeof(self) Weakself = self;
self.block = ^ {
__strong typeof(Weakself) Strongself = Weakself;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
NSLog(@"%@", Strongself.name);
});
};
self.block();
```
![image-20200810214301251](/Users/lbp/Library/Application Support/typora-user-images/image-20200810214301251.png)
字节对齐k值8的倍数。
字节对齐的原因: