Use clear and coordinated naming methods

Source: Internet
Author: User

Use clear and coordinated naming methods

1. Method naming rules. Take NSString and NSMutableString as examples.

  • If the method is newly created
    • The first name of the method should be its return type.
  + (instancetype)string;  + (instancetype)stringWithString:(NSString *)string;  + (instancetype)stringWithCharacters:(const unichar *)characters length:(NSUInteger)length;
  • Some modifiers can be added before the return type.
- (NSString *)substringFromIndex:(NSUInteger)from;
  • The attribute access method should be named by the attribute name.
- (NSUInteger)length;
  • The get prefix must be added when the return value is returned through the output parameter instead of the return value.
- (void)getCharacters:(unichar *)buffer range:(NSRange)range; 
  • If the returned value is boolean, the is prefix should be added.
- (BOOL)isEqualToString:(NSString *)aString;
  • If the method needs to be operated on the current object, it should include the verb. If there is a parameter, one or more parameters should be added after the verb.
//NSMutableString- (void)appendString:(NSString *)aString;

2. Naming rules for classes and protocols

  • Class and protocol should have a prefix
NSArray、UIView
  • If it is inheritance, the end of the subclass should be consistent with that of the parent class.
NSArray : NSMutableArray UIView : UIImageView、UITableView ..
  • The delegated agreement should contain the name of the entrusting party
UITableView : UITableViewDelegate

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.