Skip navigation.
 
mlRe: Objective-C and it's future
FROM : Damien Sorresso
DATE : Sat Jul 08 03:00:47 2006

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: damien.<email_removed>

Related mailsAuthorDate
mlObjective-C and it's future Thomas Davie Jul 8, 01:33
mlRe: Objective-C and it's future Finlay Dobbie Jul 8, 01:46
mlRe: Objective-C and it's future Shawn Erickson Jul 8, 01:48
mlRe: Objective-C and it's future Charlton Wilbur Jul 8, 01:55
mlRe: Objective-C and it's future Thomas Davie Jul 8, 02:10
mlRe: Objective-C and it's future Robert Walker Jul 8, 02:12
mlRe: Re: Objective-C and it's future Shawn Erickson Jul 8, 02:22
mlRe: Objective-C and it's future Rob Ross Jul 8, 02:29
mlRe: Re: Objective-C and it's future Shawn Erickson Jul 8, 02:41
mlRe: Objective-C and it's future Thomas Davie Jul 8, 02:42
mlRe: Objective-C and it's future Erik Buck Jul 8, 02:50
mlRe: Objective-C and it's future Kenny Leung Jul 8, 02:57
mlRe: Objective-C and it's future Gregory Weston Jul 8, 03:00
mlRe: Objective-C and it's future Damien Sorresso Jul 8, 03:00
mlRe: Objective-C and it's future Damien Sorresso Jul 8, 03:00
mlRe: Re: Objective-C and it's future Shawn Erickson Jul 8, 03:07
mlRe: Objective-C and it's future Thomas Davie Jul 8, 03:12
mlRe: Objective-C and it's future Damien Sorresso Jul 8, 03:14
mlRe: Objective-C and it's future Rob Ross Jul 8, 03:15
mlRe: Objective-C and it's future Rob Ross Jul 8, 03:18
mlRe: Re: Objective-C and it's future Shawn Erickson Jul 8, 03:23
mlRe: Re: Objective-C and it's future Shawn Erickson Jul 8, 03:25
mlRe: Objective-C and it's future Thomas Davie Jul 8, 03:28
mlRe: Objective-C and it's future Thomas Davie Jul 8, 03:40
mlRe: Objective-C and it's future Sherm Pendley Jul 8, 03:54
mlRe: Objective-C and it's future Kenny Leung Jul 8, 03:56
mlRe: Objective-C and it's future Shawn Erickson Jul 8, 04:22
ml[Moderator] Re: Objective-C and it's future cocoa-dev-admins Jul 8, 04:56
mlRe: Objective-C and it's future Thomas Davie Jul 8, 13:10
mlRe: Objective-C and it's future listposter Jul 8, 17:02
mlRe: Objective-C and it's future cocoa-dev-admins Jul 8, 17:05
mlRe: Objective-C and it's future John C. Randolph Jul 8, 18:50
mlRe: Objective-C and it's future Ryan Stevens Jul 8, 19:13
mlRe: Objective-C and it's future Scott Thompson Jul 10, 16:21
mlRe: Objective-C and it's future Andrew Satori Jul 10, 16:43
ml[Modertator] Re: Objective-C and it's future cocoa-dev-admins Jul 10, 17:13