在 Block 内如果需要访问 self 的方法、变量,建议使用 weakSelf。
__weak __typeof(self) weakSelf =self;
dispatch_async(csGetUserInfoQueue, ^{
weakSelf.lastCall = XXXX;
});
如果在 Block 内需要多次 访问 self,则需要使用 strongSelf。
__weak __typeof(self)weakSelf =self;
AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) {
__strong__typeof(weakSelf)strongSelf = weakSelf;
strongSelf.networkReachabilityStatus = status;
if (strongSelf.networkReachabilityStatusBlock) {
strongSelf.networkReachabilityStatusBlock(status);
}
};