Skip navigation.
 
mlRe: Leopard Properties and NSMutable Array
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

Related mailsAuthorDate
mlLeopard Properties and NSMutable Array Jonathan Jan 6, 02:41
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 02:53
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 03:13
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 03:16
mlRe: Leopard Properties and NSMutable Array André Pang Jan 6, 04:10
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 04:43
mlRe: Leopard Properties and NSMutable Array Scott Stevenson Jan 6, 04:49
mlLeopard Properties and 'non-nil' declaration André Pang Jan 6, 05:07
mlRe: Leopard Properties and 'non-nil' declaration Scott Stevenson Jan 6, 07:18
mlRe: Leopard Properties and 'non-nil' declaration André Pang Jan 6, 07:28
mlRe: Leopard Properties and 'non-nil' declaration Scott Anguish Jan 6, 08:33
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 12:51
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 15:55
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 18:57
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 20:05
mlRe: Leopard Properties and NSMutable Array mmalc crawford Jan 6, 20:19
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 20:20
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 20:32
mlRe: Leopard Properties and NSMutable Array Jim Correia Jan 6, 20:32
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 13, 20:13