We are back – Printing Swift code with line numbers from Xcode!

As you may have noticed – there have been no blog posts for some time. Apologies ! Everything was normal – and busy as usual. Then this thing called Covid19 came along and turned work into a slog to keep clients and companies going through the UK lockdown.

Its by no means over but at least now I can get back to sharing some of the other things I’ve experienced or been working on for the last two months. Expect SwiftUI – Expect Flutter and a range of other tips and solutions.

Starting back on the path – a problem I came across in Xcode was that I couldn’t produce SwiftUI code documentation with line numbers from a project I have been developing. Initially I thought that it would literally as simple as outputting to pdf from xcode but when I checked – no sign of line numbers.

I briefly looked at word and the use of an embedded word document inside but it suffers from the same problem as the line numbers don’t get transferred. Given that all the development had used Xcode – I had a thought that Visual Studio Code from Microsoft might offer a solution but noted that it didn’t appear to have a print option !!!!

Luckily I didn’t just give up at the stage. Instead I found a plugin called printcode which uses an embedded web server to create an intermediate file with line numbers that can be printed to pdf.

One thing though was that after installing and activating the printcode pluginĀ  the instructions for activating the plugin didn’t seem to work for me i.e F1 did nothing.

Instead I assigned my own key sequence by selecting (Code / Preferences / Keyboard Shortcuts). Then scrolling right down to find PrintCode entry – I clicked to the left of that entry and added Control Shift P to activate it.

I was able to open all the required files and generate the documentation. Pity you have to go to those lengths – hopefully this is something Xcode could easily do natively