FROM : Quincey Morris
DATE : Sun Feb 03 23:37:33 2008
On Feb 3, 2008, at 12:45, George Greene wrote:
> also, why was it necessary to use
> @property(copy, readwrite) NSString *name;
> @property(copy, readwrite) NSString *artist;
> instead of
> @property(readwrite) NSString *name;
> @property(readwrite) NSString *artist;
It isn't actually necessary. All you need to do to make the compiler
warning go away is write:
@property(assign, readwrite) NSString *name;
@property(assign, readwrite) NSString *artist;
which is what the "(readwrite)" version means anyway.
What's at stake here is whether, if you pass a *mutable* string to
setName or setArtist, it should keep a reference to the mutable string
object in the instance variable, or whether it should keep a private
copy of the string contents at that moment. Depending on the needs of
your app, one or other might be the correct answer. The compiler is
trying to warn you that the default of "assign" might not be what you
wanted.
The problem is that the object's conformance to NSCopying is a lousy
way to arbitrate the possible ambiguity. It's really got nothing to do
with NSCopying at all. And the poor wording of the warning message
isn't a help either.
I submitted a compiler bug for this a week or two ago, so we'll see if
the compiler group listens to reason. ;)
P.S. In your case, "(copy, readwrite)" looks like the proper choice,
but that's just a guess.
DATE : Sun Feb 03 23:37:33 2008
On Feb 3, 2008, at 12:45, George Greene wrote:
> also, why was it necessary to use
> @property(copy, readwrite) NSString *name;
> @property(copy, readwrite) NSString *artist;
> instead of
> @property(readwrite) NSString *name;
> @property(readwrite) NSString *artist;
It isn't actually necessary. All you need to do to make the compiler
warning go away is write:
@property(assign, readwrite) NSString *name;
@property(assign, readwrite) NSString *artist;
which is what the "(readwrite)" version means anyway.
What's at stake here is whether, if you pass a *mutable* string to
setName or setArtist, it should keep a reference to the mutable string
object in the instance variable, or whether it should keep a private
copy of the string contents at that moment. Depending on the needs of
your app, one or other might be the correct answer. The compiler is
trying to warn you that the default of "assign" might not be what you
wanted.
The problem is that the object's conformance to NSCopying is a lousy
way to arbitrate the possible ambiguity. It's really got nothing to do
with NSCopying at all. And the poor wording of the warning message
isn't a help either.
I submitted a compiler bug for this a week or two ago, so we'll see if
the compiler group listens to reason. ;)
P.S. In your case, "(copy, readwrite)" looks like the proper choice,
but that's just a guess.
| Related mails | Author | Date |
|---|---|---|
| George Greene | Feb 3, 21:45 | |
| Kyle Sluder | Feb 3, 22:41 | |
| Bill Bumgarner | Feb 3, 22:49 | |
| George Greene | Feb 3, 23:14 | |
| Bill Bumgarner | Feb 3, 23:20 | |
| George Greene | Feb 3, 23:21 | |
| Quincey Morris | Feb 3, 23:37 |






Cocoa mail archive

