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
精彩评论