Difference between @interface declaration and @property declaration

前端 未结 6 1986
忘了有多久
忘了有多久 2020-12-23 10:05

I\'m new to C, new to objective C. For an iPhone subclass, Im declaring variables I want to be visible to all methods in a class into the @interface class definition eg

6条回答
  •  执念已碎
    2020-12-23 10:48

    @interface declares the instances variables of a class in obj-c. You need it to create an instance variable. However the variable is not visible outside the class by default (as the field is by default protected).

    @property tells the compiler to specify a particular property accessor (get/set) method. However, you will need to use @synthesize to actually have the compiler generate the simple accessors automatically, otherwise you are expected to create them on your own.

提交回复
热议问题