FROM : Bill Bumgarner
DATE : Sun Jan 06 20:05:34 2008
On Jan 6, 2008, at 6:55 AM, Jonathan Dann wrote:
> What I really wanted was the ability to declare the mutable array as
> a property as a I've really grown to like the 'dot syntax'. So here
> is the solution that seems to have worked:
The dot syntax works fine for non-property based attributes. I.e. you
could drop the @property declaration below and all your code -- dot or
no dot -- would continue to work the same.
What would change, though, is that the additional metadata provided by
the @property declaration would no longer be available at runtime for
introspection purposes. At this time, there are few, if any, bits of
code that use that metadata.
I expect that'll change in the future.
> - (NSMutableArray *)array;
> {
> return array;
> }
At the least, that should be...
return [array autorelease];
... unless you have GC turned on (which the use of retain/release in
the rest of your code indicates that you likely do not).
Given the overall defensiveness of your code, you might consider
returning a copy of your array, mutable or otherwise. As it stands,
any client can grab a reference to the internal storage of your class
and change it.
return [[array copy] autorelease];
> In my main.m I can then call [array addObject:[NSString string]];
> without an error or compiler warnings.
>
> I think I could pass the setter an NSArray too as NSArray conforms
> to NSMutableCopying. Is there anything that I missed, could this go
> horribly wrong somewhere?
Nope -- that will work fine.
b.bum
DATE : Sun Jan 06 20:05:34 2008
On Jan 6, 2008, at 6:55 AM, Jonathan Dann wrote:
> What I really wanted was the ability to declare the mutable array as
> a property as a I've really grown to like the 'dot syntax'. So here
> is the solution that seems to have worked:
The dot syntax works fine for non-property based attributes. I.e. you
could drop the @property declaration below and all your code -- dot or
no dot -- would continue to work the same.
What would change, though, is that the additional metadata provided by
the @property declaration would no longer be available at runtime for
introspection purposes. At this time, there are few, if any, bits of
code that use that metadata.
I expect that'll change in the future.
> - (NSMutableArray *)array;
> {
> return array;
> }
At the least, that should be...
return [array autorelease];
... unless you have GC turned on (which the use of retain/release in
the rest of your code indicates that you likely do not).
Given the overall defensiveness of your code, you might consider
returning a copy of your array, mutable or otherwise. As it stands,
any client can grab a reference to the internal storage of your class
and change it.
return [[array copy] autorelease];
> In my main.m I can then call [array addObject:[NSString string]];
> without an error or compiler warnings.
>
> I think I could pass the setter an NSArray too as NSArray conforms
> to NSMutableCopying. Is there anything that I missed, could this go
> horribly wrong somewhere?
Nope -- that will work fine.
b.bum






Cocoa mail archive

