warning:performSelector may cause a leak because its selector is unknown

在使用 performSelector: withObject: 函数出现“performSelector may cause a leak because its selector is unknown”。


主要是警告信息,在非ARC项目中没有这个警告。如果是在某一处修改只需要加入下列代码


[code=objc]

#pragma clang diagnostic push

#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

            [vcappear performSelector:selector withObject:nil];

#pragma clang diagnostic pop


[/code]


如果在程序中多次使用可以设置一下宏

[code=objc]

#define SuppressPerformSelectorLeakWarning(Stuff) \

do { \

_Pragma("clang diagnostic push") \

_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \

Stuff; \

_Pragma("clang diagnostic pop") \

} while (0)


[/code]


如果没有返回值

[code=objc]

        SuppressPerformSelectorLeakWarning(

          [_target performSelector:_action withObject:self]

                                               );


[/code]

有返回值

[code=objc]

       

            id result;

            SuppressPerformSelectorLeakWarning(

              result = [_target performSelector:_action withObject:self]

                                               );


[/code]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值