The Weird Objective-C Method Names
In Objective-C, methods with multiple parameters look very weird, and they method name is even weirder!
Earlier in the week at Mobile Makers, we were working on a Paper, Scissors, Rock app. The user and the computer would choose one of the three (paper, scissors, or rock), and I had a method that would compare the inputs and output YES if the computer won, and NO if the computer lost.
In Ruby, this method would be simple, something like this:
def computer_won?(computer_choice, user_choice) # method implementation end
The Ruby method name in this case would simply be “computer_won?”.
Now, compare this to the same method in Objective-C:
-(BOOL)didComputerWinWithChoice:(NSString *)computerChoice humanChoice:(NSString *)humanChoice { // method implementation }
You’d think the name of the Objective-C method would be “didComputerWinWithChoice”, but that is NOT correct! The actual name of the above method is “didComputerWinWithChoice: humanChoice:”. Notice the colons, they are part of the name! Weird, huh?