Re: strong and readonly
Re: strong and readonly
- Subject: Re: strong and readonly
- From: Thomas Davie <email@hidden>
- Date: Thu, 12 Apr 2012 08:58:59 +0100
On 12 Apr 2012, at 08:50, Quincey Morris wrote: On Apr 11, 2012, at 23:58 , Thomas CLEMENT wrote: Isn't that exposing implementation details of the class that have nothing to do in its public header?
This was discussed on this list (or perhaps cocoa-dev) a week or two ago. I believe I'm summarizing the result of that discussion as follows:
The "strong" or "weak" on the @property is indeed an implementation detail in that it affects the implied declaration of a *synthesized* ivar, and the implied memory management protocol with a *synthesized* setter method. In that sense, it "really" shouldn't be on the @property but on the @synthesize instead, but that's not going to happen, in part because @synthesize is being generally de-emphasized these days.
For a readonly property, that's correct, for readwrite, it's not. The move from retain/assign to strong/weak/unsafe_unretained shows you why – "retain" does indeed describe an internal implementation detail – that the setter retains the object. Strong on the other hand describes extensional behaviour – that the class keeps a strong reference to the variable. This is important information – without it, it would be impossible to avoid strong reference cycles!
This is a slightly different discussion though. If all we're discussing is the getter, we do not need to know whether the property is strong/weak/unsafe_unretained/copy, hence, for readonly properties, it seems reasonable that you should be able to get away without specifying anything. This holds even for when you're dealing with a readwrite property internally. I can see the cleanlyness from the language design point of view of saying "all properties default to strong if nothing is specified", but at least in my mind, I would extend this to "all properties default to strong if nothing is specified in *any* corresponding property declaration". i.e. @property (readonly) A *a; would not conflict with @property (readwrite, weak) A *a; The weak specification would simply supersede the unspecified one.
Bob
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden