Xcode 9: Swift Refactoring

September 18th, 2017

Filed under: Xcode | Be the first to comment!

Xcode 9 adds Swift refactoring support, something Swift developers have been asking for since Swift’s introduction. Choose Editor > Refactor to access the refactoring options. Xcode 9 has the following refactoring options: Rename Extract function Extract method Extract variable Extract all occurrences Add missing abstract class overrides Add missing protocol requirements Add missing switch cases […]

Custom Notifications in Swift

September 8th, 2017

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

Notifications allow an object of one class to send a message for an object of another class to handle so the two classes don’t have to know about each other. The Cocoa framework has dozens of notifications, but you can also create your own. Using custom notifications involves the following steps: Get the notification center […]

Creating a Document-Based Mac Application Using Swift and Storyboards

August 7th, 2017

Filed under: Cocoa, Mac Development | 29 comments

I continue my writing on crafting modern Cocoa applications with Swift and storyboards. In this article you’ll learn about building document-based Cocoa applications by developing a simple text editor. I hope this article and project provide a gentle introduction to building document-based Cocoa applications in Swift. If you haven’t read it already, I recommend reading […]

Creating a Simple Mac Application Using Cocoa, Swift, and Storyboards

March 31st, 2017

Filed under: Cocoa, Mac Development | 3 comments

I’ve noticed there aren’t many articles or tutorials online about writing Mac apps in Swift. To help fill the void I’m writing this tutorial that guides you through the creation of a simple Cocoa app in Swift. The app converts temperatures from Celsius to Fahrenheit. Enter a temperature in Celsius, click a Convert button, and […]

Authenticating Game Center’s Local Player in a SpriteKit Game in Swift

June 6th, 2016

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

Authenticating the local player for Game Center in a SpriteKit game requires two steps. The first step is to call the GKLocalPlayer class method localPlayer, which gives you access to Game Center’s local player. The second step is to supply a closure for the local player’s authenticateHandler property. This closure takes two arguments: a view […]

Missing Required Module SwiftShims Error

April 8th, 2016

Filed under: Xcode | 3 comments

I recently migrated to a new Mac. On the new Mac I’m using an external SSD as the startup disk instead of the internal hard drive. To keep the SSD from filling up with things like photos, music, and iOS apps, I moved my user folder to the internal hard drive. This moving of the […]

Saving Game Data with NSCoding in Swift

March 23rd, 2016

Filed under: Game Development, iOS Development, Mac Development | 11 comments

I reached a point in developing LetterMiner where I wanted to save the game when the player quit so they could pick up where they left off. I didn’t find a lot of information online on saving data in SpriteKit games so I’ve decided to share what I’ve learned. I hope it helps other people. […]

Checking API Availability in Swift 2

October 12th, 2015

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

When developing Mac and iOS applications, the recommended approach to support older operating systems is to use the most recent SDK and set the deployment target to the earliest operating system your application supports. Until recently the problem with this approach is there was no way to tell at compile time if your code used […]

NSDocument initWithType in Swift 2

July 9th, 2015

Filed under: Cocoa | Be the first to comment!

I updated my document-based Cocoa application to Swift 2 in Xcode 7 using Xcode’s converter. The converter changed the initWithType method in my NSDocument subclass to the following: convenience init(type typeName: (String!)) { self.init() // Rest of initialization code here } After doing the conversion the Swift compiler crashed every time I built the project. […]

Overriding NSDocument’s initWithType Method in Swift

September 22nd, 2014

Filed under: Cocoa | 2 comments

I struggled briefly with overriding NSDocument’s initWithType: method in Swift so I’m sharing my code. Hopefully this example will help others. convenience init(type typeName: String!, error outError: NSErrorPointer) { self.init() // Place your initialization code here. }