Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ANN] Nano 1.4




On Jun 20, 2007, at 8:19 AM, Dirk Stegemann (Mailing-Lists) wrote:

Hello,

Am 20.06.2007 um 14:20 schrieb Philip Aker:

On 2007-06-20, at 01:02:05, Mike Conley wrote:

And as long as I'm on the subject of those tagged parameters, what in hell is the point of those, anyway?

Amongst other things, it's the method signature -- which I think is a part of how the language knows which selector to target.

Only the number of method parameters matters as becomes obvious when creating an SEL reference (which you would want to use, e.g. to call the selector manually).


Imagine following methods:

- (void)justAMethod:(id)firstArgument;
- (void)justAMethod:(id)firstArgument anotherArgument:(id) secondArgument;
- (void)anotherMethod:(id)firstArgument anotherArgument:(id) secondArgument;


To obtain selectors (SEL) to those methods, you'd write in code:

SEL selector1 = @selector(justAMethod:);
SEL selector2 = @selector(justAMethod::);
SEL selector3 = @selector(anotherMethod::);



Except that this is wrong.

You want:

SEL selector1 = @selector(justAMethod:)
SEL selector2 = @selector(justAMethod:anotherArgument:)
SEL selector3 = @selector(anotherMethod:anotherArgument:)


Therefore, you wouldn't be able to distinguish between

- (void)justAMethod:(id)firstArgument argVariant1:(id)secondArgument;
- (void)justAMethod:(id)firstArgument argVariant2:(id)secondArgument;

Both would boild down to

SEL selector4 = @selector(justAMethod::);
SEL selector5 = @selector(justAMethod::);

SEL selector4 = @selector(justAMethod:argVariant1:) SEL selector5 = @selector(justAMethod:argVariant2:)

and there is no problem.

The important point is that Objective C does not have tagged/named parameters. The method name is just "interwoven" with the parameters.


The fact that a method selector can be assigned to a variable (or even generated from a string) and then later used to send the corresponding message to a receiver is the power of dynamic dispatch (in C++ you can sort of use a member function pointer, but that is only valid for a given class + subclasses, and can't be used in a combination with another object that has the same signature but is from a independent class hierarchy)




Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium2 | build, mutate, evolve, animate | images, textures, fractals, art



_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: [ANN] Nano 1.4 (From: Mike Conley <email@hidden>)
 >Re: [ANN] Nano 1.4 (From: Philip Aker <email@hidden>)
 >Re: [ANN] Nano 1.4 (From: "Dirk Stegemann (Mailing-Lists)" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.