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!
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.
Does anyone know how they detect those changes? lldb says is a simple nsmutablearray (no proxy or similar), and being out of process… 🤔— Alejandro Martinez (@alexito4) 23 de junio de 2016
As usual Javi was there to give me the right answer.
@alexito4 the code that runs your extension observes changes in the dictionary and then can communicate back to Xcode via XPC.— JaviSoto.swift (@Javi) 23 de junio de 2016
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 liked this article please consider supporting me