Objective C #2 – Method Arguments

I’m still working through “Programming in Objective-C” (Stephen Kochan). Since I commute on the train, I have plenty of time during the day to read. I’m about a third done. I hope to finish in a couple of weeks. So keep in mind this is all still really new to me. I’m not trying to create a tutorial, but rather share my experience learning the language.
This one is very closely related to the previous post. This is about methods that accept arguments. If you break down this line:

– (void) setNumber: (int) n

We already know that the beginning declares that the method will not be returning any values (i.e. void). But the colon says that this method will be accepting an argument. The next bracket indicates that the method setNumber will read in an integer. The integer is named “n.” Just as a side note, the minus sign in front of (void) indicates that this is an instance method. The other option is the plus sign to indicate a class method.
Here’s a more complex one:

– (void) bounceBack: (Height *) b;

This one is a method that accepts something that is of the type class Height which had been previously declared. The asterisk is what tells us that Height is already a class. The learning curve is getting steeper now.

Technorati Tags: , , ,

Advertisements

One Response to Objective C #2 – Method Arguments

  1. Jamaal says:

    Thank you so much for this post. I have been driving myself crazy looking for a clear explanation for method arguments. Great job thanks for sharing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: