More fun scripting with Swift and Xcode: An app scaffold

One big difference between the scripter and the app developer is that a scripter usually creates a lot of lightweight apps, sometimes several in a day. Even the most prolific app developers seldom come close to that, and many just work with one or two projects.

Xcode is not nimble when it comes to creating new projects, and it is quite tedious to have to set similar aspects up every time that you do. It can also be valuable to have an ‘instant app’ to hand when you want to try some code out which you can’t run in a Swift playground.

I have therefore made myself a little Mac app scaffold, which I can use to put together a document-based app very quickly, without having to spend ages in Interface Builder wiring up text boxes.


It gives you a multi-windowed dialog, with two editable text boxes at the top for entering any text that you need, a couple of buttons to trigger action code, and two lower text output areas, the bottom of which has scrollers and can cope with large amounts of attributed text. Each of the four text areas has an Outlet, and the NSTextView in the bottom NSScrollView also has an Outlet.

I have also included my SwiftScript source file of utility calls to run shell commands, etc.

The Document.swift source includes code to save the (plain) text from the bottom scrolling text view, as a text file.

There are several ways that you can use this scaffold. One is just to customise it into your own project, although there are so many details which need to be changed in order to accommodate a change in app name, for example, that may prove too tedious.

What I have found most useful is to create a new project in Xcode in the normal way, for a Mac app which is document-based and using Swift 3.1. Save that, and close it. Then copy across the following files from MacAppScaffold to replace the files Xcode has just created in your project:

  • Base.lproj/Main.storyboard
  • ViewController.swift
  • Document.swift if you want to use the save code
  • SwiftScript.swift if you want to use any of its tools.

Having done that, there is a minimum of editing to change those to your app’s name: in Interface Builder, change the app-specific menu items, such as About MacAppScaffold, to use the correct app name; in ViewController.swift (and Document.swift if you have used that), change the app name in the commented area at the start of the file.

The complete Xcode 8.3 project is here: macappscaffold

Feel free to use this as you wish. I hope that it saves you time getting new projects started.