-
Notifications
You must be signed in to change notification settings - Fork 459
Closed
Description
#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif
#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif
weakify
和 strongify
是个非常常见的便捷生成__weak __typeof(self)weakSelf = self
和 __strong __typeof(weakSelf)strongSelf = weakSelf
的宏定义,很多库都会有类似定义。
建议这类公共方法留给用户自己去定义,或者直接在 podspec 引用最早提出这个写法的 libextobjc:pod 'libextobjc/EXTScope'
prorigorous
Metadata
Metadata
Assignees
Labels
No labels