Objective-C:在消息中使用点表示法是不好的做法吗? [英] Objective-C: Is it bad practice to use dot notation inside of a message?

查看:28
本文介绍了Objective-C:在消息中使用点表示法是不好的做法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到类似的问题,所以我决定问它(这可能更适合向程序员提问,如果是这样,我提前道歉).

I couldn't find a similar question so I decided to ask it (this may be more appropriately asked on Programmers, if so I apologize in advance).

将点符号与消息调用一起使用是不好的做法,如下所示:

Is it bad practice to use dot notation along with a message call, like so:

[self.view addSubView:otherView];

相反:

[[self view] addSubView:otherView];

我只是好奇,它看起来有点奇怪,但我看不出有什么问题.我对 Objective-C 还是比较陌生,还不熟悉任何需要注意的最佳实践.

I was just curious, it looked a tad bit strange but I don't see anything wrong with it. I'm still relatively new to Objective-C and am not familiar with any best practices of note yet.

推荐答案

没有任何问题.这只是一个文体问题.使用您喜欢的任何一种.(顺便说一句,点表示法有一个优点,即如果您使用点表示法调用未声明的属性 getter 或 setter,编译器会抛出错误,因此您可以潜在地摆脱一些奇怪的编译时的运行时错误.)

There's nothing wrong with it. It's merely a stylistic question. Use whichever one you prefer. (The dot notation, by the way, has the advantage that the compiler throws an error if you're calling an undeclared property getter or setter with the dot notation, so you can potentially get rid of some strange run-time errors at compile time.)

这篇关于Objective-C:在消息中使用点表示法是不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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