warning:performSelector may cause a leak because its selector

   

在ARC项目中使用 performSelector: withObject: 函 数出现“performSelector may cause a leak because its selector is unknown”。在stackoverflow找到了一个解决方案,地址:http://stackoverflow.com/questions /7017281/performselector-may-cause-a-leak-because-its-selector-is- unknown。

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

 

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.ticketTarget performSelector: self.ticketAction withObject: self];//此处是你调用函数的地方
#pragma clang diagnostic pop
如果在程序中多处使用,可以写一个宏定义,如下:
#define SuppressPerformSelectorLeakWarning(Stuff) \
    do { \
        _Pragma("clang diagnostic push") \
        _Pragma("clang diagnostic ignored "-Warc-performSelector-leaks"") \
        Stuff; \
        _Pragma("clang diagnostic pop") \
    } while (0)
如果没有返回结果,可以直接按如下方式调用:
SuppressPerformSelectorLeakWarning(
    [_target performSelector:_action withObject:self]
);
如果要返回结果,可以按如下方式调用:
id result;
SuppressPerformSelectorLeakWarning(
    result = [_target performSelector:_action withObject:self]
);

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2021-06-02
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
猜你喜欢
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-04-28
  • 2021-07-25
相关资源
相似解决方案