Difference between declaring an ivar in @interface and putting variable in @implementation

前端 未结 3 1116
我在风中等你
我在风中等你 2021-02-02 03:47

What is the difference between declaring an ivar within an @interface versus putting a variable within an @implementation in a .m file?



        
3条回答
  •  情书的邮戳
    2021-02-02 04:29

    Note: Historically, the interface required declarations of a class’s instance variables, the data structures that are part of each instance of the class. These were declared in braces after the @interface declaration and before method declarations:

    Instance variables represent an implementation detail, and should typically not be accessed outside of the class itself. Moreover, you can declare them in the implementation block or synthesize them using declared properties. Typically you should not, therefore, declare instance variables in the public interface and so you should omit the braces.

    (source)

提交回复
热议问题