1

I know the method listed below takes in 2 arguments, card and atTop. Why is atTop repeated twice? I know addCard is the name of the function and this function returns a void where card is a variable of type Card* and I know atTop is of type BOOL, but why is atTop twice?

- (void)addCard: (Card *)card atTop:(BOOL)atTop;
1
  • the last atTop is a reference name to the value. for example it could have been - (void)addCard: (Card *)card atTop:(BOOL)myBool; and inside the function you would've accessed it by using myBool. Commented Feb 16, 2014 at 21:44

2 Answers 2

2

That's because the full name of the method is

- addCard:atTop:

So the first atTop is part of the function name, the second atTop is the name of the parameter (both are equal in this case just by conincidence, they can be different)

Sign up to request clarification or add additional context in comments.

4 Comments

In Obj. C, all additional parameters must be associated with a name and a variable? For example, void(addCard): (Card *)card atTop:(BOOL)atTop numCards:(int)numCards? I'm used to C++ where we just have one function name and put in as many variables needed. Just wanted to make sure
@baskInEminence They don't have to be the same, no.
@baskInEminence What you say ("parameters must be associated with a name and a variable") is confusing, a parameter is 'materialized' in a variable, and a variable has a name to refer to it. You can even have a function called '- addCard:::' (without 'intermediate sub-names')
It's a method, not a function (there is a difference).
0

It is objective c notation.

(void)addCard: (Card *)card atTop:(BOOL)atTop;

Method name (selector) - "addCard:atTop:"

Parametr 1 type - "Card*" name - "card"

Parametr 2 type - "BOOL" name "atTop"

Return value - "void"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.