Let's say you have the following property:
@property foo;
Why am I seeing the following line of code to accompany the above
@property directive on various sites in discussions of @synthesize?:
@synthesize foo = _foo; // Obviously this ensures that the backing
// iVar for the foo property is named
// differently and follows the convention
// of the leading '_'.
Why is this @synthesize directive even needed? You don't need it anymore
to synthesize the setter and getter for the foo property. Secondly, if you omit it, by default, the backing iVar will be the same name as the
property prefixed with an '_'. In other words, by omiting this @synthesize line, you will automatically get what this @synthesize directive is
doing. It doesn't make sense to have it. Am I missing something?
Jon Rossen <jonr17@comcast.net> writes:
Let's say you have the following property:
@property foo;
Why am I seeing the following line of code to accompany the above
@property directive on various sites in discussions of @synthesize?:
@synthesize foo = _foo; // Obviously this ensures that the backing
// iVar for the foo property is named
// differently and follows the convention
// of the leading '_'.
Why is this @synthesize directive even needed? You don't need it anymore
to synthesize the setter and getter for the foo property. Secondly, if you >> omit it, by default, the backing iVar will be the same name as the
property prefixed with an '_'. In other words, by omiting this @synthesize >> line, you will automatically get what this @synthesize directive is
doing. It doesn't make sense to have it. Am I missing something?
There are three common reasons.
1. Automatic synthesis doesn't work on 32-bit Mac. You need the explicit @synthesize (or some other substitute) if your code needs to run there.
2. Automatic synthesis is relatively new. Historically you had to
use @synthesize (or some other substitute) on all platforms.
3. Some people distrust the possibility of hidden bugs caused by
automatic synthesis. They prefer to synthesize everything explicitly. Building with -Werror=objc-missing-property-synthesis enforces that.
Thanks very much for this detailed answer. I find it interesting that automatic synthesis doesn't work on 32 bit Macs.
Jon Rossen <jonr17@comcast.net> writes:
Thanks very much for this detailed answer. I find it interesting that
automatic synthesis doesn't work on 32 bit Macs.
How is planned obsolescence interesting?
It's despicable, possibly understandable on the part of a capitalist corporations whose sole purpose is to accumulate monetary profits.
But how can it be interesting? It's trivial evil.
Jon Rossen <jonr17@comcast.net> writes:
Thanks very much for this detailed answer. I find it interesting that
automatic synthesis doesn't work on 32 bit Macs.
How is planned obsolescence interesting?
It's despicable, possibly understandable on the part of a capitalist corporations whose sole purpose is to accumulate monetary profits.
But how can it be interesting? It's trivial evil.
"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
Jon Rossen <jonr17@comcast.net> writes:
Thanks very much for this detailed answer. I find it interesting that
automatic synthesis doesn't work on 32 bit Macs.
How is planned obsolescence interesting?
It's despicable, possibly understandable on the part of a capitalist
corporations whose sole purpose is to accumulate monetary profits.
But how can it be interesting? It's trivial evil.
It's not planned obsolescence. It's a technical limitation.
The Objective-C ABI used on 32-bit Mac does not and cannot support non-fragile ivars. (I spent almost a year trying. It just can't be done
with good performance and good binary compatibility.)
If your ivars are fragile then automatic property synthesis is unusably risky. It is too easy to do something that looks safe but actually
introduces binary compatibility bugs by changing your ivar layout.
We did support it internally, briefly. Literally nobody was able to use
it correctly. We removed it.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 67:30:19 |
Calls: | 6,654 |
Files: | 12,200 |
Messages: | 5,331,958 |