简体   繁体   中英

Objective C methods naming conventions

What name is better for the "delete" method that deletes document in database with given documentID?

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

or

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. From the code you posted you are on the right track.

Have a look at this document.

Apple Conventions

Have a look at Programming with 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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