类命名规范
- 常用Foundation类命名规范,通常以类型的缩写结尾
NSString *someStr;
NSArray *someArray;
NSDictionary *someDict;
NSDate *someDate;
NSTimer *someTimer;
- 常用UIKit类命名规范,通常也是以类型的缩写结尾
UIView *someView;
UILabel *someLabel;
UIButton *someBtn;
UIImage *someImage;
UIImageView *someImageView;
UITextField *someTextField;
UIViewController *someVC;
文件书写规范
- 头文件规范
//
// ViewController.h
// 代码规范
//
// Created by yaoliangjun on 2018/4/10.
// Copyright © 2018年 yaoliangjun. All rights reserved.
// 此处需要备注一下是哪个控制器/模型/控件
#import <UIKit/UIKit.h>
// 此处保持一个空行
@class SomeModel;
// 此处保持一个空行
@interface ViewController : UIViewController // 类名的首字母必须大写,如果有多个单词以驼峰式命名书写
// 此处保持一个空行
@property (nonatomic, copy) NSString *someStr;
@property (nonatomic, strong) SomeModel *someModel;
// 此处保持一个空行
// 属性和方法分开放
- (void)someMethod; // 方法名必须以小写字母开头
+ (NSString *)someMethod;
// 此处保持一个空行
@end
- 实现文件规范
//
// ViewController.m
// 代码规范
//
// Created by yaoliangjun on 2018/4/10.
// Copyright © 2018年 yaoliangjun. All rights reserved.
//
#import "ViewController.h"
#import "SomeModel.h"
// 此处保持一个空行
@interface ViewController ()
// 此处保持一个空行
@property (nonatomic, copy) NSString *someStr;
@property (nonatomic, assign) int age;
@property (nonatomic, strong) SomeModel *someModel;
// 此处保持一个空行
@end
// 此处保持一个空行
@implementation ViewController
// 此处保持一个空行
#pragma mark - Life Cycle Method -- 放置生命周期方法
#pragma mark - Delegate Method -- 放置代理方法
#pragma mark - Private Method -- 放置私有方法
#pragma mark - Public Method -- 放置公开方法
#pragma mark - Getter/Setter Method -- 放置getter和setter等懒加载方法
// 此处保持一个空行
@end
其他规范
- 代理命名规范
#import <UIKit/UIKit.h>
@class SomeView;
// 代理命名: 以该控件名开头,Delegate结尾
@protocol SomeViewDelegate <NSObject>
// 以控件名开头, 可以参考tableView的代理命名方式
- (void)someView:(SomeView *)someView didSelectedIndexPathAtRow:(NSInteger)row;
@end
@interface SomeView : UIView
@end