www.robkerr.com
www.robkerr.com

mobile development, cloud computing and building great software

Rob Kerr
Author

Addicted to coding since writing my first programs for the Commodore computers in the 1980s. Currently working as an independent contractor focused on native iOS development.

Share


Tags


Twitter


www.robkerr.com

Creating a Swift 3 Source Editor Extension to Increase Dev Productivity

Rob KerrRob Kerr

XCode 8 adds a new capability in version 8 that caught my eye: Source Editor Extensions.

What's a Source Editor Extension? Well in a nutshell, it's a piece of native code that can read and modify the text within an editor window. You can read more about it in the XCodeKit documentation, or watch an introductory WWDC video presentation here.

This interested me immediately because I find myself copy and pasting things like file header documentation, function documentation, UI thread dispatch boilerplate, and so on.

I'd really like to automate this kind of grunt work, and an extension would be pretty helpful, and being able to code one myself to work exactly how I work--priceless!

As a start, I created an extension with two commands:

I plan to add more to my personal extension code, but this is a great start and will let me keep adding great documentation to code with a lot less work. Sometimes it's the little things.

For the file header, I wanted to add a large banner-style header with key information (Author, date, project, copyright, etc). Also I wanted to salvage the default text XCode puts in, so I added some text parsing to the extension as well.

For the function headers, I just wanted to be have the extension add in a function doc header with the name (which I would indicate by highlighting it in the editor before triggering the extension command).

I could walk through host to create the extension step-by-step, but you can find tutorials out there via google, so go do that. Instead I'll share the source for my extension (ExpressLane) via my GitHub account here, and below a video of how the extension works in practice.

Feel free to fork my extension and make it your own. If you create some even better extension features, please share!

XCode 8 Documentation Editor Extension Demo from Mobile Tooolworks on Vimeo.

Rob Kerr
Author

Rob Kerr

Addicted to coding since writing my first programs for the Commodore computers in the 1980s. Currently working as an independent contractor focused on native iOS development.

Comments