Why are instance variables defined in the header file in Objective-C

前端 未结 6 1519
一个人的身影
一个人的身影 2021-01-12 22:36

I can understand defining the functions in the @interface of the header file, but why the instance variables? Shouldn\'t the instance variables be private, only accessible

6条回答
  •  既然无缘
    2021-01-12 23:01

    Although they are declared in the header file, all instance variable in Objective-C have @protected access by default. This means the variable is accessible within the class that declares it and any class inheriting from that class.

    Here is Apple's documentation on defining an Objective-C class: Defining Classes

    Notice the section titled "The Scope of Instance Variables".

提交回复
热议问题