IBAction 函数的命名约定
我正在做另一个 iOS 应用程序,我想知道是否有任何命名约定或关于如何命名我可以遵循的操作的良好实践。我正在考虑当用户触摸按钮时调用的函数的名称。
I am doing another iOS application and I wonder if there are any naming conventions or good practices on how to name actions that I could follow. I am thinking of names on the functions that are invoked when user e.g. touches a button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
遵循 Apple 的指导方针。过去的好建议现在已编入 ARC(自动引用计数)中,并且必须遵循 ARC 才能生成正确的代码。使用这些指南可以很好地保证您的代码面向未来,对于 ARC 来说就是如此!
苹果的指导方针
编码指南Cocoa
从方法命名部分:
名称以小写字母开头,嵌入单词的首字母大写。不要使用前缀。
这些准则有两个特定的例外情况。您可以使用众所周知的大写首字母缩略词(例如 TIFF 或 PDF)开始方法名称,并且可以使用前缀来分组和标识私有方法。
对于表示对象采取的操作的方法,名称以动词开头。
不要使用“do”或“does”作为名称的一部分,因为这些助动词很少添加含义。另外,切勿在动词前使用副词或形容词。
如果该方法返回接收者的属性,则以该属性命名该方法。除非间接返回一个或多个值,否则不需要使用“get”。
在所有参数之前使用关键字。
让论证之前的词描述论证。
Go with Apple's guidelines. What were in the past good suggestions have now been codified in ARC (Automatic Reference Counting) and are necessary to be followed for ARC to generate correct code. Using these guidelines may well future-proof your code, it did for ARC!
Apple's guidelines
Coding Guidelines for Cocoa
From the method naming section:
Start the name with a lowercase letter and capitalize the first letter of embedded words. Don’t use prefixes.
There are two specific exceptions to these guidelines. You may begin a method name with a well-known acronym in uppercase (such as TIFF or PDF)), and you may use prefixes to group and identify private methods
For methods that represent actions an object takes, start the name with a verb.
Do not use “do” or “does” as part of the name because these auxiliary verbs rarely add meaning. Also, never use adverbs or adjectives before the verb.
If the method returns an attribute of the receiver, name the method after the attribute. The use of “get” is unnecessary, unless one or more values are returned indirectly.
Use keywords before all arguments.
Make the word before the argument describe the argument.
当谈到 IBActions 的命名约定时,我没有遇到太多细节。但是,如果您要遵循苹果在其示例应用程序中设置的趋势,那么一些示例如下:
希望这会有所帮助。
I haven't come across much in the way of specifics when it comes to naming conventions for IBActions. However, if you were to follow the trend Apple seems to be setting in its sample apps, then some examples are as follows:
Hope this helps.
我想 Objective-C 中的任何方法名称都应该像阅读英文句子一样可读。下面说一下方法。
当您从左到右阅读时,它可以帮助您阅读并解释它要做什么。
查看下面的链接,
http://cocoadevcentral.com/articles/000082.php
有已经给出了很多提示。更多技巧可以在苹果的开发者库中找到。
快乐编码
I guess any method name in Objective - C should be readable like you reading an english sentence. Lets say below method.
When you read left to right it helps you to read and explains it self what it is going to do.
Check out this below link,
http://cocoadevcentral.com/articles/000082.php
There are lots of tips has been given. More tips can be found in Apple's developer library.
Happy Coding
这里是关于如何命名的讨论
IBAction
函数/方法。Here is a discussion about how to name
IBAction
functions/methods.