Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC Method naming



A feature of Objective-C is that you can have methods names that take
parameters in between. Following your example, the method name is
-setWidth:height: (the - indicates that it's an instance method) or you
can just call it setWidth:height:

A colon in a method name indicates that a parameter is expected right
there. So setWidth:height: expects two parameters. The cool thing about
this is that you can specify what kind of parameter you can expect, so
you know that the setWidth:height: method expects first the width, then
the height. The equivalent in java could be something like
setWidthAndHeight(float w, float h). Method names in java are restricted
to putting the complete name first and then all the parameters.

The java bridge does something funny with that, I'm not sure how it
works but at its simplest form I think it converts between method names
of the form setabc::: in ObjC to setabc(a, b, c) in java.

You are going to run into a lot of method names like setWidth:height:
which expect more than one parameter and the parameters are interspersed
with the method name, so you'll get used to it eventually.

eZL




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.