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.