Objective-C property and synthesize logic

后端 未结 3 1104
天涯浪人
天涯浪人 2020-12-15 08:10

What is an actual name of instance variable, say, topSpeed, as from lectures of Stanford University about the Objective-C and iOS development?

Here is the code:

3条回答
  •  一个人的身影
    2020-12-15 08:44

    1. It's a syntax sugar, let you type less word.
    2. Unlike java/c++, in obj-c you can't access variable of class. You could only call It's methods.
    3. @synthesize topSpeed = _topSpeed means You want an variable named _topSpeed and has Accessors named topSpeed and setTopSpeed.
    4. @property (nonatomic) double topSpeed; is not a pure variable declaration, It will also declare Accessors too. A pure variable of a class Foo will look like this :

      @interface Foo:NSObject{ double topSpeed; }

提交回复
热议问题