25 June 2016 2min read

XcodeTopComment, modify or remove the top comment of a file

One of the things that Apple released on WWDC was the official support for Xcode plugins. Although in a very limited way, is really nice to see Apple opening Xcode with an official framework.

I wrote a small extension that has a couple of commands to modify or remove the top comment of the file. You can check XcodeTopComment on GitHub. I can’t wait for the App Store to be open for Xcode extensions!

XcodeTopComment

Is also another example of inter-process communication, a topic that I’ve been interested lately (check xi-editor post). I even tweeted how I didn’t understand how a plain NSMutableArray could transmit the information from the extension process to Xcode.

As usual Javi was there to give me the right answer.

Of course, how dumb I am! I didn’t even thought on XcodeKit! I’m always expecting black magic, but turns out that you still need boilerplate for this to happen.

The main idea is that XcodeKit, running your extension, is the one that gives you the NSMutableArray with some KVO hooks included. When it detects changes on the array it creates a proper XPC event to send back to Xcode. Is not magic, but really awesome 😀

Anyway, check out XcodeTopComment and you know where to find me if you have some feedback 😜

If you enjoyed this post

Continue reading