C function vs. Objective-C method?

前端 未结 3 1342
清酒与你
清酒与你 2020-12-13 04:24

What is the difference between the two? If I\'m writing a program, when would I need a this:

void aFunction() {
    //do something
}

and wh

3条回答
  •  無奈伤痛
    2020-12-13 04:43

    In Objective-C each function operates on an object, like

    [myObject myFunction]

    A C method has the form:

    return-type function-name(argument1, argument2, etc) {}

    An Objective-C instance method has the form:

    -(return-type)function-name:argument1 {}

    or for a multi-argument function

    -(return-type)function-name:argument1 function-name:argument2 {}

    I always use Objective-C-style methods in Obj-C programming, even though you can still use C-type functions as well.

    I suppose the equivalent in C to [myObject myMethod:arg] might be myObject.myMethod(arg)

提交回复
热议问题