解决方法
您可以在
Objective-C Programming Language: Declared Properties的“财产实施指令”下的Apple文档中找到此信息.是否自动合成ivar取决于您使用的运行时间:
There are differences in the behavior of accessor synthesis that depend on the runtime (see also “Runtime Difference”):
- For the legacy runtimes,instance variables must already be declared in the @interface block of the current class. If an instance variable of the same name as the property exists,and if its type is compatible with the property’s type,it is used—otherwise,you get a compiler error.
- For the modern runtimes (see “Runtime Versions and Platforms” in Objective-C Runtime Programming Guide),instance variables are synthesized as needed. If an instance variable of the same name already exists,it is used.
iOS总是使用现代运行时,因此您永远不需要显式声明ivars.