9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PerformSelector で PerformSelector may cause a leak because its selector is unknown が出るときの対応

Posted at

performSelector を動的に呼ぼうとして、

    SEL selector = NSSelectorFromString(selector_string);
performSelector-leaks"
    [main performSelector:selector];

と書いたらコンパイル時に警告がでる。ググってみたところ

警告「PerformSelector may cause a leak because its selector is unknown」への対処 - 甘いものが好きです
http://d.hatena.ne.jp/captainshadow/20121114/1352834276

で、それはコードが正しくてもでてしまう警告なので、以下の対応で警告を出ないようにするのが良いらしい。

    SEL selector = NSSelectorFromString(selector_string);
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [main performSelector:selector];
    #pragma clang diagnostic pop

ちょっと気持ち悪いがしょうがないのかな。

9
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?