Files
knowledge-kit/Chapter1 - iOS/1.54.md
2020-02-25 17:46:51 +08:00

75 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 自定义工程中的头文件信息
> 我们打开 Xcode 工程的时候新建的文件顶部的信息非常的少且不是我们需要展示信息,看到很多的 GitHub 项目的顶部的头信息还是非常的花哨,所以在此记录如何写自定义模版的文章。
## 现状
```
//
// MASLayoutConstraint.h
// Masonry
//
// Created by Jonas Budelmann on 3/08/13.
// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
//
```
## 目标
```
//
// SDGFasterEncoder.h
// XQ_Persistance
//
// Author: @杭城小刘
// Github: https://github.com/FantasticLBP
// E-mail: wsbglbp@outlook.com
//
// Created by 杭城小刘 on 2019/1/23
//
```
## 动手实现
我们利用 Xcode9 新特性,自定义文本宏,来实现上述的需求。
### 步骤
1. 创建 .plist 文件
2. 添加宏名称FILEHEADER
3. 添加宏对应的值,即自定义的注释格式
4. 将文件放置于起作用的文件目录下
- 选中项目的 **.xcodeproj 文件
- 显示包内容
- 进入 xcshareddata 文件夹
- 将之前完成的 IDETemplateMacros.plist 复制到xcshareddata 下面和 xcschemes 的同级目录
- 打开 XQ_Persistance.xcworkspace
- 显示包内容
- 进入 xcuserdata 文件夹
- 将 IDETemplateMacros.plist 复制进去,生效
### 模版
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
// ___FILENAME___
// ___PACKAGENAME___
//
// Author: @杭城小刘
// Github: https://github.com/FantasticLBP
// E-mail: wsbglbp@outlook.com
//
// Created by 杭城小刘 on ___DATE___
//
</string>
</dict>
</plist>
```