1.深入研究Block用weakSelf、strongSelf、@weakify、@strongify解决循环引用
2.Objective-C 中涉及到的Block的写法:
局部变量returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
作为属性(property)@property (nonatomic, copy) returnType (^blockName)(parameterTypes);
作为方法参数:- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;
作为方法调用的参数:[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
自定义 typedef:typedef returnType (^TypeName)(parameterTypes);TypeName blockName = ^returnType(parameters) {...};
3.Swift 中Block解除循环引用的写法:
someQueue.async { [weak self] in
guard let ss = self else {
return
}
}
网友评论