January 6th, 2019
Filed under: Mac Development | Be the first to comment!
I wanted to run a Ruby tool (packaged as a gem) in a Mac app, but I didn’t want people to have to install the Ruby gem to run my app. I knew I wanted to bundle the gem in my app bundle, but I wasn’t sure how to do so. I finally figured it […]
October 24th, 2018
Filed under: iOS Development, Mac Development, Xcode | Be the first to comment!
If you create a document-based app project in Xcode, select the app target in the project editor, and click the Info button, you will see sections for imported and exported UTIs. If you have any of the following questions: What is a UTI? When would I use an imported UTI? When would I use an […]
July 17th, 2018
Filed under: Cocoa, Mac Development | 5 comments
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 […]
July 11th, 2018
Filed under: Cocoa, Mac Development, Xcode | Be the first to comment!
I ran into an issue with a new document-based Cocoa app throwing exceptions when I tried to save the document. It turns out the issue was the App Sandbox, which is turned on when you create a new Cocoa application project in Xcode. You can see the App Sandbox settings by selecting your project from […]
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 […]
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 […]
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 […]
January 12th, 2018
Filed under: iOS Development, Mac Development | Be the first to comment!
I considered writing an article about first class functions in Swift, but I came across the following article by John Sundell: First class functions in Swift Sundell’s article covers pretty much everything I would cover in an article on first class functions. The examples are good too. So I decided to link to his article […]
January 8th, 2018
Filed under: iOS Development, Mac Development | Be the first to comment!
The reduce function takes all the elements of a collection and combines them into a single value. Supply an initial value and a function or closure (unnamed function) to combine the elements. The following code demonstrates how to calculate the average for a collection of test scores: let testScores = [78, 96, 48, 65, 59, […]
January 3rd, 2018
Filed under: iOS Development, Mac Development | Be the first to comment!
The map function takes all the elements in a collection and applies a function or a closure (an unnamed function) to them. The following code demonstrates using map to multiply each element of an array by itself: let numbers = [1, 2, 3, 4, 5] let squares = numbers.map { return $0 * $0 } […]