具有多个参数的功能 [英] function with multiple arguments

查看:63
本文介绍了具有多个参数的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Objective-C的单个函数中传递多个参数?我想传递2个整数值,并且返回值也是整数.我想使用新的Objective-C语法,而不是旧的C/C ++语法.

how to pass multiple arguments in a single function in Objective-C? I want to pass 2 integer values and the return value is also integer. I want to use the new Objective-C syntax, not the old C/C++ syntax.

推荐答案

在Objective-C中,这真的非常容易.这是您在C语言中执行的方法:

In objective-c it is really super easy. Here is the way you would do it in C:

int functName(int arg1, int arg2) 
{
    // Do something crazy!
    return someInt;
}

由于它与C兼容,因此在Objective-C中仍然可以使用,但是使用Objective-C的方法是:

This still works in objective-c because of it's compatibility with C, but the objective-c way to do it is:

// Somewhere in your method declarations:
- (int)methodName:(int)arg1 withArg2:(int)arg2
{
    // Do something crazy!
    return someInt;
}

// To pass those arguments to the method in your program somewhere:
[objectWithOurMethod methodName:int1 withArg2:int2];

祝你好运!

这篇关于具有多个参数的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆