前言
Xcode导出代码文档的方式一共有三种,Doxygen, HeaderDoc 和 appledoc 。以下是三者官网链接:
这里主要说明appledoc的使用。
appledoc优点:
- 它默认生成的文档风格和苹果的官方文档是一致的,无需额外配置。
- appledoc 就是用 objective-c 生成的,必要的时候调试和改动也比较方便。
- 可以生成 docset,并且集成到 Xcode 中。
一、前置
1、下载安装appledoc
git clone git://github.com/tomaz/appledoc.git
cd ./appledoc
sudo sh install-appledoc.sh
查看版本
appledoc --version
查看所有可用的参数
appledoc --help
方法一、cd到项目文件夹下(若使用cocopods,需要定位到二级项目名下)
appledoc --no-create-docset --output ./doc --project-name 工程名 --project-company 公司名 ./
二、集成至工程中(方法二)
1、新建target
File -> New -> Target -> Aggregate -> Build Phases -> New Run Script
2、粘贴脚本,根据自己项目信息进行修改
#appledoc Xcode script
# Start constants
company="BelieverJust";
companyID="com.yhx";
companyURL="http://yhx.com";
target="iphoneos";
#target="macosx";
outputPath="xxx";#输出地址
ignorePath="xxx";#忽略地址
# End constants
/usr/local/bin/appledoc \
--project-name "${PROJECT_NAME}" \
--project-company "${company}" \
--company-id "${companyID}" \
--docset-atom-filename "${company}.atom" \
--docset-feed-url "${companyURL}/${company}/%DOCSETATOMFILENAME" \
--docset-package-url "${companyURL}/${company}/%DOCSETPACKAGEFILENAME" \
--docset-fallback-url "${companyURL}/${company}" \
--ignore "${ignorePath}" \
--output "${outputPath}" \
--publish-docset \
--docset-platform-family "${target}" \
--logformat xcode \
--keep-intermediate-files \
--no-repeat-first-par \
--no-warn-invalid-crossref \
--exit-threshold 2 \
"${PROJECT_DIR}"
3、编译项目,在outputPath文件地址下生成对应的docset文档,Xcode9之后,普遍的方法会出现此错误,但是文档已经生成了;“unable to find utility "docsetutil", not a developer tool or in PATH”。
三、问题
第一次编译项目时,有可能出现此错误“Command PhaseScriptExecution failed with a nonzero exit code”,这是由于Xcode10是默认选中的最新的New Build System(Default),在这个编译系统的环境下,打包的CI脚本一直会报错。所以要在Xcode菜单栏选择File-- Workspace Setting,把new build system(Defalt)切换到 Legacy Build System 在模拟器上运行
大部分250情况下 --ignore ".../.../.../Pods"即可。
四、注释方式
// 这个不会生成文档
/// 这是单行注释。
/** 这也是单行注释 */
/*! 同样是单行注释 */
/**
* 这也是单行注释,
* 第二行会接上第一行。
*/
/**
* 下面是常用的markdown语法
* 一、无序列表: (每行以 '*'、'-'、'+' 开头):
* * this is the first line
* * this is the second line
* * this is the third line
*
* 二、有序列表: (每行以 1.2.3、a.b.c 开头):
* a. this is the first line
* b. this is the secode line
*
* 三、多级列表:
* * this is the first line
* a. this is line a
* b. this is line b
* * this is the second line
* 1. this in line 1
* 2. this is line 2
*
* 四、标题:
* # This is an H1
* ## This is an H2
* ### This is an H3
* #### This is an h4
* ##### This is an h5
* ###### This is an H6
*
* 五、链接:
* 普通URL直接写上,appledoc会自动翻译成链接: [https://believerJust.com](http://example.net/)
* [这个]([http://example.net/](http://example.net/)) 链接会隐藏实际URL.
*
* 六、表格:
* | header1 | header2 | header3 |
* |---------|:-------:|--------:|
* | normal | center | right |
* | cell | cell | cell |
*/
/**
* @brief 这里是方法的简介。该Tag不能放到类注释里。
* @exception UIColorException 这里是方法抛出异常的说明
* @warning 这里是警告
* @bug 这里是bug
* @param value 这里是参数说明
* @return 这里是返回值说明
*/