Re: RS: Reply about NSObject members class, isMemberOfClass, isKindOfClass
Re: RS: Reply about NSObject members class, isMemberOfClass, isKindOfClass
- Subject: Re: RS: Reply about NSObject members class, isMemberOfClass, isKindOfClass
- From: Mike Abdullah <email@hidden>
- Date: Mon, 10 Sep 2007 14:34:19 +0100
OK, now that makes more sense. But you have to ask yourself whether
the extra effort is really worth it. What you're doing here is to try
and break outside the normal conventions for object-oriented
programming for a tiny performance gain. Write your code to treat the
array as immutable regardless and then if you run into performance
problems consider an optimisation such as this.
Also, your code below is likely to leak as myArray was probably
originally autoreleased. Instead try:
if ( ![myArray isMutable] ) myArray = [[myArray mutableCopy]
autorelease];
Mike.
On 10 Sep 2007, at 13:03, Gerriet M. Denkmann wrote:
On 8 Sep 2007, at 08:04, email@hidden wrote:
On Sep 7, 2007, at 4:04 PM, Roland Silver wrote:
The reason I need to know whether an object is a mutable array is
that in a current program I have bugs involving APPARENTLY creating
NSMutableArrays that turn out not to be mutable, and I need help to
track down where the bugs are.
In any case, it should never be necessary to check whether an
array is
mutable or immutable. The method signature that you get the object
from will tell you how you should treat it; for example, the
result of
a method declared as returning an NSArray should never be treated as
an NSMutableArray.
I have a method which gets an NSArray, but I know that sometimes it
really gets supplied with a mutable thing.
This method needs to do something with the array. So it would like
to do:
if ( ![myArray isMutable] ) myArray = [myArray mutableCopy];
As you said, it is not *necessary* to check the mutablity of
myArray - but it cleary would be more efficient.
Kind regards,
Gerriet.
_______________________________________________
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:
40mikeabdullah.net
This email sent to email@hidden
_______________________________________________
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