Because Objective-C 2.0 has properties , good syntax is for getting and setting values for instance variables. Since Clang 3.1, all properties that are not dynamic, not just with an explicit getter or without a custom getter and setter, are automatically synthesized for ivars. And since ARC has weak / strong annotations for properties that are used by ARC to determine the memory management logic of automatically synthesized properties.
Properties can still be synthesized manually , for example. for the readonly property supported by ivar and returning the default value, for example.
Sometimes properties are also useful if they are not synthesized at all. I found several use cases when I use this behavior:
- A custom getter and setter that use a custom ivar to store the actual value and perform some additional actions.
- Dynamic property, for example. in subclasses
NSManagedObject. - A readonly property that simply passes through a property of an object stored in another property (for example, private).
Question: Does it make sense to annotate these non-synthesizable properties with weak / strong depending on their actual use or not? What is the best practice?
(https://twitter.com/kubanekl/status/427142577310408704)