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;//1 [UIView animateWithDuration:1 animations:^{ StrongSelf;//2 [self.view doSomething];//use self }]; }
//swift 2.2 self.closure = { [unowned self] in self.doSomething() }
Stay hungry,stay foolish.