I have a class A that provides a way to get and set an object of type Foo . In a property language, I usually declare this in an interface:
@property (nonatomic, strong) Foo * foo;
This (in modern ObjC) generates both accessors and ivar, _foo for storage.
If I want to do user work in accessors, I can implement one or both of them myself. But what if I not only want to do individual work, I really do not want Ivar? In other words, I am doing something else with the Foo object, for example, passing it back and forth to another internal object with which I am a member. I really don't need to store the repository for Foo in instance A at all.
I seem to have two options:
- Declare a property, implement both accesses, and simply ignore the fact that the compiler creates storage for
_foo and never uses it. - I explicitly declare my helpers:
- (Foo *)foo and - (void)setFoo:(Foo *)foo in the interface, as I used in the up-to-date ObjC.
The former seems inelegant at runtime, and the latter seems inelegant in the declaration (where I probably now have a combination of properties and properties similar to accessories).
Is there a way to declare a property and use it as a pure declaration?
objective-c cocoa
Ben zotto
source share