禁止某个Method

有时,不希望别人使用某个父类方法,比如,写了一个继承NSObject的类,不希望别人用init方法实例化。

那么可以通过这个方法禁止掉,并且报错提示给别人:

1
2
3
4
5
6
 #ifndef DOXYGEN_SHOULD_SKIP_THIS

 // Disallow init and don't add to documentation
 - (id)init __attribute__((unavailable("init is not a supported initializer for this class.")));

 #endif


-

Copyright © 2015 - 徐佳琦 - Powered by Octopress