標籤:class code http tar com get
在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]);