Objective-C 新手。尝试通过 void 函数传递参数,猜猜我不能这样做?
我是 Objective C 的新手。我试图在我的实现文件中使用参数编写一个 void 函数,但是 xcode 不喜欢这样。我做了一些研究,看来我做不到。
这就是我基本上想做的事情:
-(void)findMilesLeft(float x, float y)
{
float gallons = x;
float miles = y;
}
我将在另一个 void 函数中调用此 findMilesLeft - 我相信我会将其称为:
-(void)changeSUV
{
[self findMilesLeft(20, 100)];
}
显然我已经尝试过这种语法,但它对我不起作用......有什么方法可以正确执行这个?
显然这里没有计算,但我认为这个想法很清楚。
谢谢, 约翰
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的语法是:
然后你这样称呼它:
如果你还没有这样做,你可能应该阅读这个文档:):
Objective-C 简介
The correct syntax is:
And then you call it like that:
If you didn't do it yet, you should probably read this document :):
Introduction to Objective-C