Re: Appropriateness of assign attribute and -fobj-gc-only
Re: Appropriateness of assign attribute and -fobj-gc-only
- Subject: Re: Appropriateness of assign attribute and -fobj-gc-only
- From: Quincey Morris <email@hidden>
- Date: Sun, 21 Sep 2008 15:00:10 -0700
On Sep 21, 2008, at 14:04, Rick Mann wrote:
But the warning is:
"warning: 'assign' attribute on property 'portName' which implements
'NSCopying' protocol not appropriate with -fobjc-gc-only"
So, is it really inappropriate? It seems very appropriate to assign
the pointer rather than allocate a new object and copy it,
especially for immutable objects.
No, it's not.
The issue is that a object-pointer property might *either* be an
attribute (i.e. a value which should be copied) *or* a relationship
(i.e. a connection to another object which should not be copied), and
there's no syntactic difference.
For some inexplicable** reason, Apple has chosen to try to tell the
difference based on whether the object implements NSCopying, which
really has nothing to do with it.
The solution is, of course to specify "copy" or "assign" on every such
property. That's a good idea anyway, since it documents the kind of
property, and makes you stop to think about which is the correct
behavior for the property.
--
** Actually, I think it's not totally inexplicable. NSString* and
NSNumber* are possibly the most common property types, and they're
almost always attributes, rarely relationships, so it's almost always
a bad idea to use "assign" for them. My guess is that this warning
exists primarily to remind you to specify "copy" for strings and
numbers.
Incidentally, I bug-reported this warning and was mostly rebuffed,
except that in gcc 4.2 the warning now reads:
"warning: default 'assign' attribute on property 'portName' which
implements 'NSCopying' protocol not appropriate with -fobjc-gc-only"
which is infinitesimally more accurate. I'm very proud of that
"default" -- it proves that even we little people can change the
world. :)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden