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。

主要是警告信息,在非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]
);

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

时间: 2024-11-09 00:08:16

warning: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

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/pe

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

【转】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是接

performSelector的原理以及用法

一.performSelector调用和直接调用区别下面两段代码都在主线程中运行,我们在看别人代码时会发现有时会直接调用,有时会利用performSelector调用,今天看到有人在问这个问题,我便做一下总结, [delegate imageDownloader:self didFinishWithImage:image]; [delegate performSelector:@selector(imageDownloader:didFinishWithImage:)withObject:sel