Austin Rude's Blog

Programming with Swift, iOS, macOS, etc.

Drawing custom views in Swift Playgrounds

2016-12-26 Programming
Easy template to start working on a custom view in Swift Playgrounds Getting the details right in a custom view can require tens or even hundreds of iterations. Building an iOS project, loading the app in the simulator, and checking the results is just too slow. Swift Playgrounds allow you to write your drawing code, and see your results almost instantaneously in Xcode. Just use the following as a starting template, and start drawing! Continue reading

State machines in Swift

2016-09-25 Programming
The problem You have a large and complicated if/switch statement You keep copying parts of the if/switch block around the codebase You keep needing to add/tweak the conditions for edge cases If you run into issues like these, it might be a valid use case for a finite-state machine. A state machine can help you simplify the code, and make the logic more explicit! My experience of the issue When working on my app Nap Slide I ran into an issue handling transitions between alarm clock states. Continue reading

Spacemacs cheatsheet for Vim users

2016-09-23 Programming
This cheatsheet is geared more towards past Vim users, and is focused on Spacemacs specific shortcuts (not Vim). Help SPC h SPC Help SPC ? Search bindings Programming SPC s j Show Imenu (variables, classes, enums, etc.) SPC d d Lookup word at cursor with dash Z Z Save buffer and close SPC j = Indent buffer or selected region z o Open fold z c Close fold z r Open folds Continue reading

Accessing audio (and other) files stored in the Xcode asset catalog with Swift

2015-10-18 Programming
When working on my “Nap Slide” iOS app, I needed to embed various .wav files in the application. Being new to iOS development, using the asset catalog seemed to be the obvious choice (Google/StackOverflow has led me to believe developers with previous Xcode experience would use application bundles). Accessing images stored in the asset catalog is easy and well documented, accessing other file types (a feature added as of Xcode 7) is not. Continue reading