Re: Calling a method on objects in an NSArray
Re: Calling a method on objects in an NSArray
- Subject: Re: Calling a method on objects in an NSArray
- From: Clark Cox <email@hidden>
- Date: Thu, 13 May 2004 15:45:58 -0400
On May 13, 2004, at 14:02, David Piasecki wrote:
>
Yes, I just found it myself. Actually, IMHO, the manual isn't all that
>
great, but I also can't stand overly-descriptive method names (i.e.
>
makeObjectsPerformSelector or doThatThingThatYouDoWithThatOtherThing)
>
in object oriented languages. Ah well... maybe I'll get used to it
>
soon enough.
>
>
Unfortunately, makeObjectsPerformSelector:withObject only allows you
>
to send a single object as a parameter, and that object must be an
>
Obj-C object. I wanted to pass an NSSize structure. I'm working around
>
it, but it's just kind of annoying.
You could add a category like so (warning, composed in Mail, no
errorchecking, etc.):
@interface NSArray(PerformWithSizeExtension)
- (void)makeObjectsPerformSelector:(SEL)aSelector
withSize:(NSSize)argument;
@end
@implementation NSArray(PerformWithSizeExtension)
- (void)makeObjectsPerformSelector:(SEL)aSelector
withSize:(NSSize)argument
{
NSEnumerator *enumerator = [self objectEnumerator];
id object;
while(object = [enumerator nextObject])
{
void (*implementation)(id,SEL,NSSize) = [object methodForSelector:
aSelector];
if(implementation != NULL)
{
implementation(object, aSelector, argument);
}
}
}
@end
--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.