Swift Snippets 0: Introduction and Contents

This article introduces two series of articles published here which I hope will be of interest to the beginning to intermediate level Swift programmer. They are primarily aimed at those using Swift 3.1 in Xcode for macOS projects, but may well have relevance for iOS and other platforms.

I am not an expert in Swift, but all the code shown works, unless otherwise stated. If you know how to do it better, or more idiomatically, then please comment and I’ll be delighted to include your improvements, duly credited.

The complete set of Swift Snippets is also available here: SwiftScrapbook2
(and in Downloads above) as a Tinderbox document. You can edit them, add your own code snippets, and use the document to keep all reusable code. It does require a copy of Tinderbox 7 from Eastgate Systems, although you can also use it to a limited extent from Eastgate’s Storyspace.

swiftscrap32

Swift Snippets – Swift 3.1 code for common or useful tasks

1: Strings, Attributed Text, Arrays
2: Interface, NSDocument, Files
3: Preference Files, Property Lists, JSON
4: Numbers, Dates, Unified log, Objective-C
5: Bundles, Process, Background activity, Shell commands

Previous articles about scripting and coding in Swift, with longer code workthroughs:

Building a better console replacement: an exercise in Xcode 1
Building a better console replacement: an exercise in Xcode 2 – more lessons in Swift learned the hard way
Making a better app to check your Mac’s security systems
More fun scripting with Swift and Xcode: the signature shuffle
More fun scripting with Swift and Xcode: cheating with AppleScript
More fun scripting with Swift and Xcode: alerts and file save
More fun scripting with Swift and Xcode: max factoring
More fun scripting with Swift and Xcode: Swift Documentation Markup
More fun scripting with Swift and Xcode: quirky commands
More fun scripting with Swift and Xcode: Radio buttons and more
Blowhole advanced: writing a command tool in Swift 3, and more
Beyond Scripting in Swift: turning Consolation into a full-blown app
Beyond Scripting in Swift: Preferences
Beyond Scripting in Swift: JSON and the Golden NSDictionary
Beyond Scripting in Swift: Implementing JSON to CSV conversion
Help Help: 1 Help Crafter – help authoring tools (HAT) for Sierra
Help Help: 2 What has happened to Help?
Help Help: 3 What the docs don’t tell you
Making an Installer package the easier way
More fun scripting with Swift and Xcode: Reading Plists, building popups, and more
More fun scripting with Swift and Xcode: Sorting with a closure
More fun scripting with Swift and Xcode: Finding apps, and calls that don’t fail
Beyond Scripting in Swift: Keychains lost in translation
More fun scripting with Swift and Xcode: An app scaffold
Beyond Scripting in Swift: Who’s afraid of the big, bad buffer?
Normalising strings in Swift: scripting Apfelstrudel and beyond
How to normalise strings, and a new command tool to help
More fun scripting with Swift and Xcode: opening docs and converting text
More fun scripting with Swift and Xcode: huge popups, and strings too smart
More fun scripting with Swift and Xcode: Encoding conversion without tears
Beyond Scripting in Swift: Running background activities
Beyond Scripting in Swift: Reading and writing property lists
More fun scripting with Swift and Xcode: An app in a couple of hours
More Scripting in Swift: Styling Attributed Text
Beyond Scripting in Swift: Dates, Steppers, and parsing log entries
Beyond Scripting in Swift: Sets, Lies, and Videotape
Beyond Scripting in Swift: Of characters and closures
More fun scripting in Swift with Xcode: files and deep traversal
Beyond Scripting in Swift: A preference sheet

I will also add an index here in due course.