performSelector may cause a leak because its selector is unknown

后端 未结 19 2471
小蘑菇
小蘑菇 2020-11-22 01:54

I\'m getting the following warning by the ARC compiler:

\"performSelector may cause a leak because its selector is unknown\".

Here\'s what

19条回答
  •  孤城傲影
    2020-11-22 02:37

    In the LLVM 3.0 compiler in Xcode 4.2 you can suppress the warning as follows:

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        [self.ticketTarget performSelector: self.ticketAction withObject: self];
    #pragma clang diagnostic pop
    

    If you're getting the error in several places, and want to use the C macro system to hide the pragmas, you can define a macro to make it easier to suppress the warning:

    #define SuppressPerformSelectorLeakWarning(Stuff) \
        do { \
            _Pragma("clang diagnostic push") \
            _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
            Stuff; \
            _Pragma("clang diagnostic pop") \
        } while (0)
    

    You can use the macro like this:

    SuppressPerformSelectorLeakWarning(
        [_target performSelector:_action withObject:self]
    );
    

    If you need the result of the performed message, you can do this:

    id result;
    SuppressPerformSelectorLeakWarning(
        result = [_target performSelector:_action withObject:self]
    );
    

提交回复
热议问题