Class extension vs class category

前端 未结 4 901
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 04:53

Class extensions @interface Class () are a lot more powerful and can inject variables into the class. Categories @interface Class (Category) can\

4条回答
  •  天涯浪人
    2020-12-02 05:13

    The main difference is that with an extension, the compiler will expect you to implement the methods within your main @implementation, whereas with a category you have a separate @implementation block. So you should pretty much only use an extension at the top of your main .m file (the only place you should care about ivars, incidentally) -- it's meant to be just that, an extension.

提交回复
热议问题