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: Chris Hanson <email@hidden>
- Date: Fri, 7 Sep 2007 17:46:28 -0700
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.
I have since written a predicate that tests an object for
mutablearrayness, based on a method (removeLastObject) that is (per
last release of Xcode) apparently unique to NSMutableArray, plus the
try/catch/finally hack.
Xcode has nothing to do with the methods that NSMutableArray
supports. Xcode is just the IDE; the frameworks that make up Mac OS X
are what actually contain all of the various classes.
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. Similarly, the signature of a method that you're
passing an object to will tell you how it's going to treat the object;
for example, a method that takes an NSMutableArray parameter should
never be passed an NSArray.
One common case where people get tripped up is -copy versus -
mutableCopy. They expect sending -copy to an NSMutableArray to return
an NSMutableArray; however, the result will actually be an NSArray.
You need to explicitly ask collections to perform mutable copies by
sending them -mutableCopy.
-- Chris
_______________________________________________
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