nef Xcode extension

nef Xcode extension

A lot of cool features have been added to nef since its launch. Between them, nef lets you:

  • Create Xcode Playgrounds with support for third-party libraries.
  • Compile and verify your documentation written as Xcode Playgrounds.
  • Generate Markdown files from Xcode Playgrounds.
  • Create a Jekyll microsite from Xcode Playgrounds.
  • Create Carbon snippets from Xcode Playgrounds.

Although nef user experience is great, it is working from the command line, and, in some cases, it will be easier to use nef directly in Xcode. In 2016, Apple launched Xcode source editor; it opens Xcode to write extensions to make the editor do new things. At this point, you might be able to figure out what the next step is… integrate nef into Xcode context. Boom!

Xcode extension: nef

Xcode source editor extension lets you add your own commands as a part of the Editor menu. After the nef plugin installation, you will notice a new section with actions in the menu panel.

nef Xcode extension will be installed in Editor menu

Between the nef features, we have considered that export carbon snippets is a neat feature to integrate into Xcode. This enables you to make a code selection and export it to a snippet, without going out from Xcode, and with the full power of nef. Nice!

How to export code selection using nef plugin

It gets better! You can take advantage of Xcode tools for improving your productivity. How? You can associate a keyboard shortcut to each nef action from Xcode > Preferences... > Key Bindings

nef Xcode extension: Associate a key binding to nef actions

How can I install the plugin?

nef extension is available on Mac App Store; however, you can install it manually by downloading the last binary from the releases section on GitHub.

To complete the installation, you should enable nef extension from System Preferences > Extensions > Xcode Source Editor.

How to enable nef Xcode extension

How has the nef plugin been developed?

It is an exciting project made in pure Swift 5, using Swift Package Manager and SwiftUI with some new Apple frameworks like Combine. Although it is an extension for Xcode, you must use an app to contain and deliver it. Nevertheless, this umbrella app will be useful to do the hard work, and our plugin calls it to complete the actions.

You can find this project on GitHub; when you download it, you will find two targets — one for the extension and another for the main app. Extension app manages all the commands, and will call the main app to complete the work. On the other hand, nef app has an entry point by each extension command; a custom URL scheme handles it.

Each view controller has been done using SwiftUI and following an MVVM architecture, with the new Combine framework. The result is code that is easier to read and maintain, perfectly integrated with the UI and the Data. You can find a complete example in the Preferences view.

Conclusions

Xcode source editor extension is an excellent choice to integrate custom works into Xcode, although it is not free of embarrassing limitations. As usual, your extension is sandboxed, and Xcode only gives you access to the text and metadata that they have considered essential. You do not get access to the project structure, user’s files on disc, or any other data in the current Xcode project. Despite these security, stability limitations, we can do great things like this nef integration, and distribute it on the Mac App Store to the world.

In this Xcode extension, you will find a complete real product; it has been made using SwiftUI and Combine together external dependencies using Swift Package Manager.

Head over to GitHub repo and stay tuned for news on future releases!

For more information, or to get involved, check out the following resources for Bow and nef. Comments, questions, issues, and PRs are welcome!

nef is proudly sponsored by 47 Degrees, a Functional Programming consultancy with a focus on the Scala, Kotlin, and Swift Programming languages, which support their active development.

Ensure the success of your project

47 Degrees can work with you to help manage the risks of technology evolution, develop a team of top-tier engaged developers, improve productivity, lower maintenance cost, increase hardware utilization, and improve product quality; all while using the best technologies.