1:oc中blcok是一个匿名函数,常用于回调
2:oc中blcok的三种常见定义:
#import "HttpTool.h" typedef void(^myBlock)(NSString *name); @interface HttpTool () //typedef定义法 - (void)httpToolBlock:(myBlock)callBlock; // void(^block名字)(参数列表) @property (nonatomic,copy)void(^callBlock)(NSString *name); // 方法的block定义 //(void(^)(NSString *str))callBlock - (void)blockFunc:(void(^)(NSString *name))callBlock; @end
3:对于block中经常会注意循环引用的问题:最好的办法是使用weckself,常见写法:
#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
1. __weak XJViewController *weakSelf = self; 2. __weak typeof(self) weakSelf = self; 3. __weak __typeof(self)weakSelf = self;
3:使用内存图来判断是否循环引用了:
:
意见反馈邮件:1415429879@qq.com 欢迎你们的阅读和赞赏、谢谢!