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