ios - 为什么属性在不合成的情况下仍然有效?

标签 ios objective-c properties

我在.h

@property (nonatomic) NSString *yourMom;

然后在.m

禁止合成! 在viewdidload中直接访问:

_yourMom = @"Sally";

这无需合成即可工作。为什么?

最佳答案

Objective-C @properties are synthesized by default when not explicitly implemented.

Unless you specify otherwise, the synthesized instance variable has the same name as the property, but with an underscore prefix. For a property called firstName, for example, the synthesized instance variable will be called _firstName.

请阅读此document来自苹果。它包含您需要的全面信息。

关于ios - 为什么属性在不合成的情况下仍然有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41711350/

相关文章:

iOS7 XIB 问题。顶部和底部的空白

ios - Swift Firebase UIRefreshControl

objective-c - 类和父类(super class)之间的双向通信

ios - Titanium - 在 iOS native 模块中包装 ADTECHMobileSDK 的 CoreData 错误

c# - 在编译时获取类的属性名称,无需对象实例化

c# - 以高性能方式审核和验证对 C# 类和结构属性的更改

ios - componentsseparatedbystring 在 Swift 中由多个分隔符

ios - 将框架/边界/约束从一个 View 复制到另一个 View

iphone - 自定义 UIActionSheet

Jaxb EclipseLink/MOXy : Is it possible to specify the names of get/set methods