iOS待阅奏折iOS 深度好文iOS扩展

Xcode8最新特性一(Xcode Source Editor

2016-06-16  本文已影响2933人  三角君

Xcode 8已经发布2天了,并且beta版本已经可以下载,迫不及待的看了官方文档,终于还是被我看到了一个让人兴奋的特性:Xcode Source Editor Extensions

介绍

New Xcode extensions for the source editor let you customize your coding experience. Use extensions to navigate within your editor’s text, and select, modify, and transform your code. Bind your favorite extensions to a keyboard shortcut to make common reformatting tasks a snap. Xcode includes a new template so you can easily create editor extensions and distribute them on the Mac App Store, or sign your extensions with your Developer ID to share them online. And because extensions run in a separate process, Xcode stays safe and stable.

备注:为了不丢失翻译过程中的准确度,上述文字不翻译,挺容易懂得

准备

  1. 下载Xcode 8
  2. 安装additional system components(Xcode 会自动处理,不用手动)
  3. 安装完毕后, 打开terminal,然后执行命令sudo /usr/libexec/xpccachectl
  4. 重启电脑,这个只需要一次(意味着以后开发的Extension不需要了)

起航

一、创建一个Project,并且选中OS X - Application - Cocoa Application

1.png

二、第1步结束之后会创建一个Mac OS程序,我们完全不用管它。选中Targets,点击底部的“+”,然后继续选择OS X - Application Extensions - Xcode Source Editor Extentsion

2.png

三、接下来我们会得到2个文件,其中SourceEditoCommand.swift就是我们需要处理的。

3.png

四、 在SourceEditorCommand.swift愉快的编写你的代码吧!

五、编写好你的代码之后,运行extension scheme,当弹出"Choose an app to run"菜单时,选择Xcode 8,打开任意源文件,你的插件就会在"Editor"菜单出现。

recording.gif

实战

XPAlignment
Emojify

大坑

  1. Xcode 8这个新特性出来后,以前所有能在Xcode 7及以下版本运行的插件都用不了了,非常悲剧的消息!
  2. Xcode Source Editor Extension必须依赖某一个Mac OS程序存在,不像以前的插件一样独立存在!
  3. 在Editor菜单下有时看不到我们开发好扩展菜单!
上一篇下一篇

猜你喜欢

热点阅读