Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果要在类中全局使用 ivar,但永远不会被其他类访问,我们还应该使用属性吗?
这通常是一个好主意,因为生成的访问器将为您处理诸如内存管理和 KVO 之类的事情。您可以将该属性放在类扩展中,这样其他类就无法使用它。
对我来说,这取决于实例变量将用于什么。
如果它是表示某些数据的对象,那么我将始终使用属性。
如果它只是简单BOOL地通过类中的几个方法进行一些内部簿记,那么我不会为它创建属性。
BOOL