Objective-C:消息语法与点语法;有什么不同? [英] Objective-C: message syntax vs. dot syntax; what's the difference?

查看:101
本文介绍了Objective-C:消息语法与点语法;有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用的是@synthesize foo;,则以下内容之间有什么区别:

If I'm using @synthesize foo;, what's the difference between the following:

// message syntax
[myObj setFoo:5];
[myObj foo];

// dot syntax
myObj.foo = 5;
myObj.foo;

我喜欢点语法的一致性,但是我不知道它是否在做我应该关注的事情.

I like the consistency of the dot syntax but I don't know if it's doing something I should be I concerned about.

任何其他信息都会有很大帮助.

Any additional information would be a great help.

推荐答案

使用点语法和使用消息语法之间没有功能上的区别.

There is no functional difference between using dot syntax and using message syntax.

我发现使用消息语法与整个语言更加一致,而点语法的实现只是为了方便那些使用Java的语言的程序员.

I find that using message syntax is more consistent with the language as a whole and that dot syntax was just implemented as a convenience to programmers who were coming over from languages that used it (Java comes to mind).

我要问的是:无论选择哪个,都要与之保持一致. 请勿混合使用单个属性设置器! (多参数二传手显然是免税的.)

All I ask is: Whichever one you choose, be consistent with it. Do not mix and match single property setters! (Multiple-argument setters are obviously exempt).

这篇关于Objective-C:消息语法与点语法;有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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