è¦åãPerformSelector may cause a leak because its selector is unknownãã¸ã®å¯¾å¦
ã»ã¬ã¯ã¿ãæå®ãã¦ãªãã¸ã§ã¯ãã«ã¡ãã»ã¼ã¸ãéãå¦çã«ã¤ãã¦ã
SEL sel = @selector(doSomething); if ([obj respondsToSelector:sel]) { [obj performSelector:sel]; }
ãã®ãããªã³ã¼ãããã«ãããã¨ãARCæå¹æã«performSelector:ã®è¡ã«ã¤ãã¦æ¬¡ã®è¦åãåºãã
PerformSelector may cause a leak because its selector is unknown
æ示å@selectorã«ããã»ã¬ã¯ã¿ãæå®ããã®ã§ã¯ãªãSELåå¤æ°ã使ç¨ããå ´åã«ã®ã¿è¦åãåºããå®éã次ã®ãããªå ´åã«ã¯è¦åã¯åºãªãã
if ([obj respondsToSelector:@selector(doSomething)]) { [obj doSomething]; }
if ([obj respondsToSelector:@selector(doSomething)]) { [obj performSelector:@selector(doSomething)]; }
åå
ãã®è¦åãåºãåå ã«é¢ããAppleã¸ã®åãåããçµæãä¸è¨è¨äºã«è¨è¼ããã¦ããã®ãçºè¦ãåèã«ãªãã¾ããããããã¨ããããã¾ãã
ããããªãã-performSelector:ã§ã¯ã¼ãã³ã°åºããããã
ãçµå±ã2ã¤ããã¤ã³ã·ãã³ãã®1ã¤ã使ã£ã¦Appleã«åãåããããã-performSelector:ããã®è¿ãå¤ãã³ã³ããã¼ã«ã§ããªãã¦ã¯ã¼ãã³ã°åºããã ãã
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [self performSelector:ac]; #pragma clang diagnostic popãã§ç¡è¦ããããã«ãã¡ãã£ã¦ã¼ããã¦è¿çãè¿ã£ã¦ãã¾ãããã¾ããçµå±å ã ã®Toll-free bridgeç¨ã®å¯¾å¿ã§ãããã£ã¦äºã¿ããã§ãã
ãæ£å¼åçãªãã§ãçãããå®å¿ãã¦ä¸è¨å¯¾å¿ã§ããã¾ãããã
対å¦æ¹æ³
以ä¸ã®ãã¼ã¸ãåèã«ãã¤ã¤å¯¾å¦æ¹æ³ãæ´çããã*1
- iphone - performSelector may cause a leak because its selector is unknown - Stack Overflow
- セレクタの配列をSEL *selectors = malloc(sizeof(SEL)*100); として添字で取り出し...
- iPhoneアプリ開発、号外 ARCでいくぜ!|テン*シー*シー
æ¹æ³1: è¦åãå±æçã«ç¡è¦ãã
次ã®ããã«è¦åã®å¯¾è±¡ã¨ãªãç®æãæã¿è¾¼ãå½¢ã§#pragmaæ令ãæ¸ããã¨ã«ãããè¦åã®ç¨®é¡ãæå®ãã¦å±æçã«è¦åãç¡è¦ããããã«è¨å®ãããã¨ãã§ããã*2
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [obj performSelector:sel]; #pragma clang diagnostic pop
æ¹æ³2: ã©ã³ã¿ã¤ã é¢æ°ã使ç¨ãã
performSelector:ã§ã¯ãªãã©ã³ã¿ã¤ã é¢æ°objc_msgSend()ã«ããã¡ãã»ã¼ã¸ãéä¿¡ããã¨è¦åãåºãªãã
#import <objc/message.h> // objc_msgSend()ã使ç¨ããããã«å¿ è¦ // ä¸ç¥ if ([obj respondsToSelector:sel]) { objc_msgSend(obj, sel); }
æ¹æ³3: performSelector:withObject:afterDelay:ã使ç¨ãã
performSelector:ã®ãããã«performSelector:withObject:afterDelay:ã使ãã¨è¦åãåºãªããperformSelector:withObject:afterDelay:ãå¤ãè¿ããªããã¨ã¨ããperformSelector:ããã®è¿ãå¤ãã³ã³ããã¼ã«ã§ããªãã¦ã¯ã¼ãã³ã°åºããã¨ããAppleããã®åçå 容ãèããã¨ããã®çµæã¯å½ç¶ã®ãã®ã¨ãããã ããã
if ([obj respondsToSelector:sel]) { [obj performSelector:sel withObject:nil afterDelay:0.0f]; }