warning:performSelector may cause a leak because its selector

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]
);
时间: 2024-08-29 13:19:55

warning:performSelector may cause a leak because its selector的相关文章

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

在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. 主要是警

iOS疯狂详解之warning: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 diagnosti

ios之"performSelector may cause a leak because its selector is unknown"警告原因及其解决办法

问题描述 项目中使用到了从字符串创建选择器,编译时发现警告:"performSelector may cause a leak because its selector is unknown"(因为performSelector的选择器未知可能会引起泄漏),为什么在ARC模式下会出现这个警告? 经过搜索后,在Stackoverflow上发现了一个令人满意的答案.见http://stackoverflow.com/questions/7017281/performselector-may

PerformSelector may cause a leak because its selector is unknown

本人使用的方法,需要针对每个warning进行添加 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" id value = [weakSelf performSelector:getSel];//产生warning的代码 #pragma clang diagnostic pop ---------------------------------另一种方

iOS PerformSelector may cause a leak because its selector is unknown

开始的写法: SEL selctor = NSSelectorFromString(_interaction.functionName); [self performSelector:selctor withObject:nil]; 解决办法: 编译器警告这个是由原因的,这种警告很少出现,甚至可以简单的忽略,而且解决也很容易.具体方法如下: SEL selctor = NSSelectorFromString(_interaction.functionName); IMP imp = [self

【IOS 开发】Object - C 面向对象高级特性 - 包装类 | 类处理 | 类别 | 扩展 | 协议 | 委托 | 异常处理 | 反射

一. Object-C 对象简单处理 1. 包装类 (1) 包装类简介 NSValue 和 NSNumber : -- 通用包装类 NSValue : NSValue 包装单个 short, int, long, float, char, id, 指针 等数据; -- NSNumber 包装类 : 用于包装 C 语言数据类型; NSNumber 方法 : -- "+ numberWithXxx :" : 将特定类型的值包装成 NSNumber; -- "- initWithX

ios之block循环引用

在 iOS 4.2 时,苹果推出了 ARC 的内存管理机制.这是一种编译期的内存管理方式,在编译时,编译器会判断 Cocoa 对象的使用状况,并适当的加上 retain 和 release,使得对象的内存被合理的管理.所以,ARC 和 MRC 在本质上是一样的,都是通过引用计数的内存管理方式. 然而 ARC 并不是万能的,有时为了程序能够正常运行,会隐式的持有或复制对象,如果不加以注意,便会造成内存泄露!今天就列举几个在 ARC 下容易产生内存泄露的点,和各位童鞋一起分享下. block 系列

【转】clang warning 警告清单(备查,建议直接command + F 速查 )

Warning Message -WCFString-literal input conversion stopped due to an input byte that does not belong to the input codeset UTF-8 -WNSObject-attribute __attribute ((NSObject)) may be put on a typedef only, attribute is ignored -Wabstract-vbase-init in

Objective-C中一种消息处理方法performSelector

Objective-C中调用函数的方法是“消息传递”,这个和普通的函数调用的区别是,你可以随时对一个对象传递任何消息,而不需要在编译的时候声明这些方法.所以Objective-C可以在runtime的时候传递人和消息. 首先介绍两个方法 SEL和@selector 根据AppleObjective-C Runtime Reference官方文档这个传递消息的函数就是 id objc_msgSend(id theReceiver, SEL theSelector, …) theReceiver是接