function with multiple arguments

后端 未结 4 1662
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 05:02

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 synta

4条回答
  •  萌比男神i
    2021-02-06 05:39

    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;
    }
    

    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];
    

    Best of luck!

提交回复
热议问题