In Objective-C 2.0, I usually make an assign property for ivars that are primitive types like float. Then it occurred to me that I can access them from outside the class with obj->variable notation. I imagine that this is bad practice: is it?
In Objective-C 2.0, I usually make an assign property for ivars that are primitive
Share
Yes, it’s bad practice because it breaks encapsulation of your class’ implementation details. The
@propertydeclaration is a public API statement (“my class provides a property of type, e.g.float), not an implementation statement (“my class has afloatinstance variable”). Clients of your class’ API should not know its implementation details lest you be prevented from changing those details without breaking client code.