Instance variables declared in ObjC implementation file

后端 未结 3 707
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 04:46

I was watching the WWDC ARC introduction video and I saw something I\'ve never seen in ObjC before when some Apple engineer talked about a Stack example.

The followi

3条回答
  •  遥遥无期
    2020-11-29 05:40

    This is indeed a new language feature, and if you must declare your ivars (rather than simply declaring properties and letting the compiler generate ivars for you) it's a good practice. Your header files in theory should only expose public interface for your classes; everything else belongs in the implementation.

    One caveat is that implementation-file ivars are not visible to subclasses, which can occasionally be a little bit awkward if you have manually generated setters and getters that you need to subclass.

提交回复
热议问题