instance variables in @interface; header vs implementation

前端 未结 2 1459

Is there any difference between declaring a private instance variable in the header vs declaring it in the implementation?

in TestObj.h

@interface TestOb         


        
2条回答
  •  独厮守ぢ
    2021-02-19 22:21

    The preference is generally to place private instance variables and properties in the private class extension (in the .m) and leave the public interface file (.h) for those properties and methods that are truly part of the public interface.

    It helps isolate implementation details from the public interface and makes everything much cleaner. It also ensures that external classes do not inadvertently alter the private variables of this class.

    See Class Extensions Extend the Internal Implementation.

提交回复
热议问题