我在.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/