ios 开发资料

动手自己写一个 xcode 8 插件(Xcode Source

2016-08-31  本文已影响3094人  supersmalltalk

动手自己写一个 xcode插件  (暂时需要注释功能,所以简单的写一个注释插件)

-----Xcode Source Editor Extensions-----


-----------------------------------------------------------------------

ps:

插件显示,需要开发者证书(免费 or 付费)

Extensions for Xcode 8

据说10.11需要打开terminal,然后执行命令sudo /usr/libexec/xpccachectl 一次(建议重启)

插件是可以在Xcode的Preferences的Key Bindings中设置快捷键的


-----------------------------------------------------------------------

开始:

1:创建Project,并且选中OS X - Application - Cocoa Application,

就像穿件一个iOS 项目和其他插件(today,share,action.....)等等一样的关系,

2:添加Target,选择OS X - Application Extensions - Xcode Source Editor Extension

这样就创建了插件,并生成了两个(默认名称为SourceEditorCommand,SourceEditorExtension)

这里名称是可以改的,改了之后只需要在Target的info.plist中修改

XCSourceEditorCommandClassName 对应 SourceEditorCommand

XCSourceEditorExtensionPrincipalClass 对应 SourceEditorExtension

我们看到XCSourceEditorCommandDefinitions这个数组

这个地方就是这个插件所有的功能配置的地方,使用XCSourceEditorCommandIdentifier区分

我们主要撰写的代码在SourceEditorCommand中,需要运行插件的时候,会回调

- (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation completionHandler:(void (^)(NSError * _Nullable nilOrError))completionHandler

{

completionHandler(nil);

}

这个XCSourceEditorCommandInvocation *invocation中就有我们需要的全部信息,选择了哪一行,那一列,内容,等等等等

运行效果如上,选择两个功能的时候,使用

NSString *identifier = invocation.commandIdentifier;

来区分identifier是哪一个XCSourceEditorCommandIdentifier以调取不同的功能代码


-----------------------------------------------------------------------

Demo:

WTxcodeToolBox (注释功能)

最近用xcode 8,

1:CommentStatement 插件

包含功能:

(1):CommentStatement 注释掉代码(即xcode原有的Comment Statement功能,因为xcode 8有bug 所以...)等效于 "command + /"; Screenshot

(2):DocumentAdd 添加注释 (超级简单的山寨VVDocumenter)...暂时只能识别Objective-C Screenshot

上一篇 下一篇

猜你喜欢

热点阅读