开发者

Objective-C equivalent of a flash action script function

Learning basic Objective-C and have a few beginner questions. How would I define and implement a method wh开发者_如何学Cich takes two (or three) arguments within my class? I find the syntax to pass multiple arguments into a method really confusing. I would really appreciate any help. thanks.


Apple's "The Objective-C Programming Language" document provides a nice overview of Object Messaging including an explanation of the syntax.


Here's an example of a simple 2-argument method implementation:

-(int)myMethodThatMultipiesThisNumber:(int)x byThisOne:(int)y
{
    return x * y;
}

You would invoke it like:

int z = [myObject myMethodThatMultipliesThisNumber:6 byThisOne:9];

Is that what you're looking for?

Edit: Based on your comment below, it seems like you're missing a fundamental feature of Objective-C messaging - that the method name is interleaved with the arguments. Check out this page from The Objective-C Programming Language for all the detail you need.


Whether or not you are interested in iPhone programming, I would watch the first three classes of Paul Hegarty's CS193P class from Stanford.

Those first three classes have very little iPhone specific stuff, instead, classes 1 and three go over the features and syntax of Objective C, and class 2 goes over basic use of Xcode (which, if you want to do Objective C work, is likely the IDE you will be using). Other than the fact that it goes VERY fast (which may actually be what you are looking for) you would be hard pressed to find a better "quick overview" of Objective C.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜