iOS-Xcode自定义模板

iOS项目中开发过程中如果有代码规范,每次新增文件都会必须添加需要的代码,因此需要对文件的代码模板重新按照项目的要求修改.

Xcode系统模板的路径是/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/,文件夹里面有文件模板File Templates和工程模板Project Templates,如果修改UIViewController模板路径如下:

iOS-Xcode自定义模板_第1张图片
FlyElephant.png

选择UIViewController文件夹下的模板文件:


iOS-Xcode自定义模板_第2张图片
FlyElephant.png

代码自定义模板:

`//
// FILENAME
// PROJECTNAME
//
// Created by FULLUSERNAME on DATE.
//COPYRIGHT
//

import "FILEBASENAME.h"

@interface FILEBASENAMEASIDENTIFIER ()

@end

@implementation FILEBASENAMEASIDENTIFIER

pragma mark - LifeCycle

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    }

  • (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    }

  • (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    }

  • (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    }

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

pragma mark - Public

pragma mark - Private

pragma mark - Accessors

pragma mark - Request

@end
`

新建控制器:


iOS-Xcode自定义模板_第3张图片
FlyElephant.png

创建完成之后模板:

`//
// FEViewController.m
// DynamicDemo
//
// Created by keso on 2017/4/22.
// Copyright © 2017年 FlyElephant. All rights reserved.
//

import "FEViewController.h"

@interface FEViewController ()

@end

@implementation FEViewController

pragma mark - LifeCycle

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    }

  • (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    }

  • (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    }

  • (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    }

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

pragma mark - Public

pragma mark - Private

pragma mark - Accessors

pragma mark - Request

@end
`

同时可以自定义设置模板,在文件模板下新建自定义文件夹,然后将Cocoa Touch Class.xctemplate拷贝进入新建文件下:


iOS-Xcode自定义模板_第4张图片
FlyElephant.png
iOS-Xcode自定义模板_第5张图片
FlyElephant.png

你可能感兴趣的:(iOS-Xcode自定义模板)