简体   繁体   English

Objective C方法命名约定

[英]Objective C methods naming conventions

What name is better for the "delete" method that deletes document in database with given documentID? 对于使用给定documentID删除数据库中的文档的“删除”方法,什么名称更好?

1) -(void) deleteDocumentWithID:(NSString *) documentID error:(NSError **)error; 1) -(void) deleteDocumentWithID:(NSString *) documentID error:(NSError **)error;

or 要么

2) -(void) deleteDocumentByID:(NSString *) documentID error:(NSError **)error; 2) -(void) deleteDocumentByID:(NSString *) documentID error:(NSError **)error;

Your naming conventions are completely up to you, as mentioned in the apple doc try and be as descriptive as possible with your method names so any third party looking at your code (header file) will be able to get an idea quickly on what the method does. 您的命名约定完全取决于您,如Apple doc中所述尝试并尽可能使用您的方法名称描述,因此任何查看您的代码(头文件)的第三方都能够快速了解​​该方法的内容确实。 From the code you posted you are on the right track. 从您发布的代码中,您走在正确的轨道上。

Have a look at this document. 看看这个文件。

Apple Conventions Apple公约

Have a look at Programming with Objective-C 看看Objective-C编程

  • Method names do not have a prefix 方法名称没有前缀
  • Method should start with a lowercase letter 方法应以小写字母开头
  • camel case is used for multiple words 骆驼案例用于多个单词
  • If a method takes one or more arguments, the name of the method should indicate each parameter 如果方法接受一个或多个参数,则方法的名称应指示每个参数
  • Error should be the last parameter to the method 错误应该是方法的最后一个参数

在此输入图像描述

By and with depends on you 随着和取决于你

 -(void) deleteDocumentWithID:(NSString *) documentID error:(NSError **)error;

 -(void) deleteDocumentByID:(NSString *) documentID error:(NSError **)error;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM