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

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?

Enjoy the article? Join over 14,500+ Swift developers and enthusiasts who get my weekly updates.

  • SimulaMan

    Objective-C follows the Smalltalk school of method naming. Many other languages follow the Simula school of method naming. Either style is “weird” if you’re used to the other.

    (When you see “computer_won?(x, y)”, how do you know which argument is what? It’s less typing but it’s not so “simple” when I have to read it!)

    Ruby is arguably the weirdest of all, because it steals a lot of syntax from both schools! 🙂

  • I love every language that has named parameter like this ^^