1、一般写法
__weak typeof(self) weakSelf = self;
__strong typeof(self) strongSelf = weakSelf;
2、Rac做法
2.1, @unsafeify(self); @strongify(self);
@autoreleasepool {} __attribute__((objc_ownership(none))) __typeof__(self) self_weak_ = (self);;
{
@autoreleasepool {}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
__attribute__((objc_ownership(strong))) __typeof__(self) self = self_weak_;
#pragma clang diagnostic pop
;
}
2.2, @weakify(self); @strongify(self);
@autoreleasepool {} __attribute__((objc_ownership(weak))) __typeof__(self) self_weak_ = (self);;
{
@autoreleasepool {}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
__attribute__((objc_ownership(strong))) __typeof__(self) self = self_weak_;
#pragma clang diagnostic pop
;
self.title;
}
3、YYKit做法
3.1 @weakify(self);@strongify(self);
@autoreleasepool{} __attribute__((objc_ownership(weak))) __typeof__(self) weak_self = self;;
@autoreleasepool{} __typeof__(self) self = weak_self;;
注意关键词的使用 objc_ownership
4、总结一下语法格式
@autoreleasepool {}
typeof(self) __attribute__((objc_ownership(none))) unsafeself
typeof(self) __attribute__((objc_ownership(weak))) weakself
typeof(self) __attribute__((objc_ownership(strong))) strongself
__attribute__((objc_ownership(weak))) __typeof__(self) weakself
__typeof__(self) strongself
问题:
放在block内的 ,无论是typeof(self)
还是 __typeof__(self)
这两种写法,此处的self 不会造成强引用吗?
网友评论