开发者

New to Objective-C. Trying to pass arguments through a void function, guessing I can't do that?

开发者 https://www.devze.com 2023-04-08 22:42 出处:网络
I am new to Objective C. I am trying to write a void function 开发者_开发问答in my implementation file with arguments however xcode doesn\'t like that. I did some research and it appears I can\'t do t

I am new to Objective C. I am trying to write a void function 开发者_开发问答in my implementation file with arguments however xcode doesn't like that. I did some research and it appears I can't do that.

This is what I am trying to do basically:

 -(void)findMilesLeft(float x, float y)
{

    float gallons = x;
    float miles = y;
}

I would be calling this findMilesLeft within another void function- I believe I would call it as:

 -(void)changeSUV
 {
   [self findMilesLeft(20, 100)];
 }

Obviously I have tried this syntax and it didn’t work for me… is there some way I can execute this correctly?

The calculations arent in here obviously but I think the idea is clear.

Thanks, John


The correct syntax is:

-(void)findMilesLeftWithX:(float)x andY:(float)y
{
    float gallons = x;
    float miles = y;
}

And then you call it like that:

 -(void)changeSUV
 {
   [self findMilesLeftWithX:20 andY:100];
 }

If you didn't do it yet, you should probably read this document :):

Introduction to Objective-C

0

精彩评论

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

关注公众号