objective c difference between functions and methods

前端 未结 2 918
一整个雨季
一整个雨季 2020-12-05 00:31

Is there any dramatic difference between functions and methods in Objective -C?

2条回答
  •  遥遥无期
    2020-12-05 01:00

    First, I'm a beginner in Objective-C, but I can say what I know.

    Functions are code blocks that are unrelated to an object / class, just inherited from c, and you call them in the way:

    // declaration
    int fooFunction() {
        return 0;
    }
    
    // call
    int a;
    a = fooFunction();
    

    While methods are attached to class / instance (object) and you have to tell the class / object to perform them:

    // declaration
    - (int)fooMethod {
        return 0;
    }
    
    // call
    int a;
    a = [someObjectOfThisClass fooMethod];
    

提交回复
热议问题