Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BRPickerViewMacro 中 weakify 和 strongify 与其他库重复定义 #227

Closed
codingiran opened this issue Apr 11, 2021 · 0 comments
Closed

Comments

@codingiran
Copy link

codingiran commented Apr 11, 2021

#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

weakifystrongify 是个非常常见的便捷生成__weak __typeof(self)weakSelf = self__strong __typeof(weakSelf)strongSelf = weakSelf的宏定义,很多库都会有类似定义。

建议这类公共方法留给用户自己去定义,或者直接在 podspec 引用最早提出这个写法的 libextobjcpod 'libextobjc/EXTScope'

@codingiran codingiran changed the title BRPickerViewMacro 中关于 weakify 和 strongify 与其他库重复定义 BRPickerViewMacro 中 weakify 和 strongify 与其他库重复定义 Apr 11, 2021
@agiapp agiapp closed this as completed Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants