NCF NCF - 4 years ago 160
Objective-C Question

objective c difference between functions and methods

At the moment I am studying 'blocks' in Objective-C and the blocks


Enable to define functions and treat them as objects


Well, is there any dramatic difference between function and method?

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download