user1069449
user1069449

Reputation: 13

ObjectiveC: something between return value and method name

I am trying to understand the meaning of that "something" before the method name in objC. Here an example:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
      shouldContinueAfterSelectingPerson:(ABRecordRef)person 
                                property:(ABPropertyID)property 
                              identifier:(ABMultiValueIdentifier)identifier

The method name is shouldContinueAfterSelectingPerson, the method has three parameter and has a return value (BOOL) but what is the role of peoplePickerNavigationController:(ABPeoplePickerNavigationController *)?

It isn't the return value, it isn't the method parameter (because cames before the method name), and so what is it?

Upvotes: 0

Views: 207

Answers (7)

nacho4d
nacho4d

Reputation: 45118

Actually, in this case the method name is

peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:

And it has 4 arguments.

This is kind of a special case since this is a method of a protocol. In general you don't call/send methods of protocols, they are called and you are supposed to implement them to react appropriately to a certain situation.

As said in other answers too, you are given the peoplePickerNavigationController because it could be the case you have various controllers and you don't want to do the same thing for all of them. :) You use it to differentiate between them.

If you were to call this method by your own then having the first argument would be some how redundant (Since in most cases you will already know that information)

Hope it helps.

Upvotes: 1

DanZimm
DanZimm

Reputation: 2578

In objective c the method is split up into 4 components (or so I would guess as this is how I see it)

I'll break up this method:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
      shouldContinueAfterSelectingPerson:(ABRecordRef)person 
                                property:(ABPropertyID)property 
                              identifier:(ABMultiValueIdentifier)identifier

the - signifies that it's an instance method, you need to allocate an instance of this class to use it.

the (BOOL) signifies that it should return a BOOL, YES or NO.

the method is defined by a selector uid, peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:

That is the full method name unlike what you have said.

the last part are the parameters. Those are pretty self explanatory.

Upvotes: 2

JeremyP
JeremyP

Reputation: 86661

No, the method name (or strictly speaking, the selector) is

peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:

It is just that its first parameter is the navigation controller sending the message. This is so that the receiver knows which object sent the message. It's a standard paradigm for delegate methods, so one object can be delegate for more than one other object.

Upvotes: 0

iandotkelly
iandotkelly

Reputation: 9134

Presuming you are talking 'in general' and not specifically about this method.

Well it is all part of the signature of the method. Each part with a colon (:) before it is a string which is all part of the method name in effect.

Upvotes: 0

Rafael Steil
Rafael Steil

Reputation: 4697

The method name is peoplePickerNavigationController, not "shouldContinueAfterSelectingPerson". In fact, the method's signature is peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:, because in Objective-C method names / signatures are composed of all arguments.

Upvotes: -1

jamapag
jamapag

Reputation: 9318

Method name is not shouldContinueAfterSelectingPerson but peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:, and it takes 4 arguments.

Upvotes: 0

Michael Dautermann
Michael Dautermann

Reputation: 89519

The role of the peoplePickerNavigationController: parameter is to allow multiple ABPeoplePickerNavigationController objects to use a single instance of your object as a delegate.

And this way, if there are multiple ABPeoplePickerNavigationController objects, you'll know which picker did the picking (and called into your delegate method).

Hope this helps clear up your confusion!

Upvotes: 0

Related Questions