Xcode8 beta版已经开始支持编辑插件的编写,并对Xcode进程进行了保护,这就意味着以前通过Alcatraz管理Xcode插件的方式在8以后将不复存在。
下面就先简单的介绍Xcode8编辑器插件如何编写。
本文章编写时所用的Xcode版本为 Version 8.0 beta 6 (8S201h)
如果你是 EI Capitan 用户,请先运行sudo /usr/libexec/xpccachectl
,然后重启Xcode
新建 macOS 下的 Cocoa 项目

命名为 XcodeExt

新增 Target : Xcode Source Editor Extension


命名为 XcodeExtTest

左边XcodeExtTest下的三个文件就是我们写插件要用到的文件

这个时候我们可以先什么都不写,运行看一下有什么效果。你会发现Editor
菜单下面并没有出现你写的插件。我特意看了下控制台输出,发现有这么一句
2016-09-04 23:03:22.506 Xcode[6410:108875] IDESourceEditorExtension: Xcode Source Editor Extension does not meet code signing requirement: me.ocean.XcodeExt.XcodeExtTest ((null)), Error Domain=DVTSecErrorDomain Code=-67050 "code failed to satisfy specified code requirement(s)" UserInfo={NSLocalizedDescription=code failed to satisfy specified code requirement(s)}
应该是 beta6 没有证书不让调试,于是我就生成了一个mac的开发证书,再次运行,就可以看到Editor
下面有插件名称显示出来了

要同时给XcodeExt和XcodeExtTest两个Target签名,才能编译通过
网友评论