Working with File Wrappers in Swift

July 17th, 2018

Filed under: Cocoa, Mac Development | Be the first to comment!

Back in 2010 I wrote an article on working with file wrappers. Recently I needed to work with file wrappers, and I noticed the file wrapper code is much different in Swift so I figured working with file wrappers in Swift would be a good topic for an article. This article assumes you’re creating a […]


Getting Started with Unit Testing in Swift 4

June 13th, 2018

Filed under: Cocoa, iOS Development, Mac Development, Xcode | Be the first to comment!

One of the most read articles on this blog is An Introduction to Swift Unit Testing. The article is almost four years old and uses Swift 1. Because of that I have decided to build upon that article here, updating the code to Swift 4 and adding an example project to unit test. The Project […]


Handling Swipe Gestures in a SpriteKit Game

February 16th, 2018

Filed under: Game Development, iOS Development | Be the first to comment!

When you create a SpriteKit Xcode project, the GameScene.swift file contains functions to handle touch and/or mouse events, depending on the type of SpriteKit project you create. You can also use swipe gestures in SpriteKit games. Supporting swipe gestures requires you to perform two tasks. The first task is to create a swipe gesture recognizer. […]


Checking Modifier Keys in Swift

January 22nd, 2018

Filed under: Cocoa, Mac Development | Be the first to comment!

Checking for modifier keys (Command, Control, Option, and Shift) when handling events is different in Objective-C and Swift. In Objective-C you perform a bitwise AND operation to check if modifier keys were held down. In Swift you check if the event’s modifier flags contains the specific modifier key. The following example demonstrates how to check […]


Swift Functional Programming: Pure Functions

January 15th, 2018

Filed under: iOS Development, Mac Development | 2 comments

A pure function doesn’t reference any data outside of the function. If you supply a given input to a pure function, it always returns the same value. The following is a simple example of a pure function: func increment(value: Int) -> Int { return value + 1 } The increment function is pure because it […]