iOS __weak __strong WeakSelf StrongSelf

在block中常常会用到self,可是会造成循环引用。这时候就需要这样来解决这个问题:

#define WeakSelf __weak typeof(self) weakSelf = self
#define StrongSelf __strong typeof(weakSelf) self = weakSelf
//OC
- (void)aFunc:(id)sender { WeakSelf;//
[UIView animateWithDuration: animations:^{
StrongSelf;//
[self.view doSomething];//use self
}];
}
//swift 2.2
self.closure = { [unowned self] in
self.doSomething()
}
上一篇:SharePoint使用jsom查询当前用户信息


下一篇:300M无线路由器 TL-WR842N - TP-LINK官方网站