功能和方法之间的客观差异 [英] objective c difference between functions and methods

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

问题描述

Objective -C中的函数和方法之间是否有显着差异?

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

推荐答案

首先,我是Objective-C的初学者,但是我可以说我所知道的.

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

函数是与对象/类无关的代码块,只是从c继承而来,您可以通过以下方式调用它们:

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

这篇关于功能和方法之间的客观差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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