Subject: Re: Help with implementing delegates
On Mar 27, 2009, at 7:48 PM, Drew Lawson wrote:
According to Greg Guerin:
albert jordan Mobility wrote:
In Foo, I have set up the following delegate method
-(void) test: (dgtest *) sender:didFinish: (BOOL) complete
You just gave me a newbie headache.
How is that original parsed?
To parse it you need to know:
A method name doesn't need to have a word before each colon. You
could have a method like this:
- (void)printThreeIds:(id)first :(id)second :(id)third;
You would call it like this:
[myObject printThreeIds:self :nil :@"hello"];
Although valid syntax, this practice is discouraged since it makes the
method name less readable.
The other thing you need to know is that you don't have to specify the
type of a method argument. The type will default to id. So the above
method could have been declared like this:
- (void)printThreeIds:first :second :third;
A handy fact to remember is that the number of colons in a method name
is the number of arguments the method takes. So if you meant it to
take two arguments and you see three colons, you know you have a typo.
Putting all the above together, the faulty method declaration would be
- (void)test:(dgtest *)sender // argument named "sender" is of
:didFinish // argument named "didFinish" is of type id
:(BOOL)complete; // argument named "complete" is of type
The OP was able to write a perfectly good looking method that used the
sender and complete arguments, never realizing he'd accidentally
introduced an argument called didFinish.
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
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 maillists@xxxxxxxxx