Re: Objective-C and it's future
Re: Objective-C and it's future
- Subject: Re: Objective-C and it's future
- From: Damien Sorresso <email@hidden>
- Date: Fri, 7 Jul 2006 20:00:47 -0500
On 7 Jul, 2006, at 7:50 PM, Erik Buck wrote:
One such example is the NSArray foundation class. I would like to be
able to express that I specifically have an NSArray containing only
objects of a certain type. This would allow me to (a) let the
Just out of curiosity, why do you want this ? How often do you put
the wrong kind of object in a collection in practice ? What
determines "wrong" ? Do you have some objection to -
respondsToSelector: in cases when you can't know in advance what
objects might be in a collection that was provided to your code ?
It seems curious, since when using an `NSArray', you're using an
immutable object. The only opportunity you'd have to screw up is
during initialization, which you really shouldn't. If type-checking
is necessary, do type-checking. That's what `isKindOfClass:' is for.
But in any case, you could easily sub-class `NSArray' or
`NSMutableArray' to do this. Just overload `NSMutableArray's
`addObject:' method to do something like this.
- (void)addObject:(id)anObject
{
if( [anObject isKindOfClass:_arrayClass] ) [super addObject:anObject];
else {
// Do whatever...
}
}
`_arrayClass' is, of course, an instance variable for your
`NSMutableArray' subclass.
--
Damien Sorresso
Mac OS X Developer
Computer Infrastructure Support Services
Illinois State University
E-mail: email@hidden
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden