My Garage Tracker app was my first foray into Swift application development. The app allows users to manage vehicles belonging to their household or business, record service history, document receipts and to set reminders for future servicing.
The Swift programming language was announced by Apple during WWDC in June 2014 and has gradually increased in maturity and stability over the preceding few months.
I had studied the fundamentals of the language almost from the day it was released using the excellent Swift language guide. This provided a great starting point to familiarise myself with some of the newly introduced language constructs and key differences from Objective-C. Undoubtedly however, the best way to really grasp the language was to build a real application. This post documents some of my observations and lessons learned.
My Garage Tracker
Whilst the app is fairly simple, it incorporates a few more advanced features of the iOS platform including Core Data persistence and Apple’s in-app purchase framework.
My Garage Tracker targets iOS8 exclusively, allowing the use of the latest and greatest iOS features, without the overhead of backwards compatibility for this internal project.
iOS8 adds some great new features for app developers to use, and whilst My Garage Tracker doesn’t use them all, there are plenty of planned updates to take advantage of these in future releases.
Xcode 6 & Swift
Xcode 6 was released by Apple to coincide with the announcement of Swift. It includes various improvements to the development workflow, debugging tools and of course, support for the Swift language.
Swift brings a cleaner, functional programming style to the familiar Apple APIs. New types and language constructs also allow developers to structure applications in new ways, not previously possible with Objective C.
Xcode 6 provides a few useful tools for the Swift developer; when developing a project, occasionally you may need to try out a few lines, just to see if something works. Interactive Playgrounds provide an area, separate from a full project to try out code before adding it to a project. A playground provides output in real-time, including UI component rendering, making it especially useful for testing UI transformations and animations.
Changes from iOS7
Previously with iOS7, the user did not need to grant permission for an app to fire local notifications. My Garage Tracker uses local notifications to trigger reminder alerts at various times. The updated iOS8 permissions model requires the app to prompt the user to grant permission before a local notification may be scheduled. This was fairly painless since the app targets iOS8 exclusively.
One of the most exciting features introduced with the Swift language are a handful of new types. These include more advanced Enumerations, Structs, Tuples and various other changes to types familiar to an Objective C developer. The new types allow the developer to structure an application and model data in ways not previously possible.
All scenes throughout My Garage Tracker use autolayout to define sizes, positions and relationships between user interface elements. By carefully specifying scalable dimensions and using the newly introduced storyboard “size classes”, the design can scale to work with the variety of screen sizes across Apple devices, including iPad. Size classes allow the behaviour of a layout to be tweaked for a generic device size and orientation (e.g. iPad portrait), without specifying explicit dimensions or rules.
As Apple introduce additional screen sizes with new devices, autolayout and size classes will become an exceptionally useful way of supporting specific layouts without needing to redevelop the entire app layout or introduce layout “hacks” for a particular device.
Core Data with Swift
The CoreData APIs are virtually identical to those of Objective-C, so their usage is immediately familiar. My Garage Tracker uses Core Data to store vehicle data and related history and reminder information.
The cleaner style of the Swift language means some of the more verbose method calls appear much neater, and ultimately code is easier to read, write and maintain. I did encounter a few issues with transient managed properties, which work fine when using Objective C. These are known issues and are likely to be resolved in later Swift releases.
PDF Vector Images
All images (except the app icon) use PDF vector images. Selecting an image group from the project asset catalog, and choosing the “template image” render option allows a tint colour to be applied. Creating vector images rather than raster formats (png/jpg) removes the need to produce multiple images at 1x, 2x and 3x sizes to suit each screen resolution. This is especially useful for commonly used assets such as icons. Xcode will automatically produce each size at build time from a single 1x sized vector image. We found this Xcode 6 feature so useful, we curated a set of PDF icons for use in any project. Check out the GitHub repository.
Whilst I could be regarded as a latecomer to Swift (now over six months old), since the day of release, Apple has made incremental improvements and subtle changes to the language.
During this period, there has been much discussion regarding the stability and suitability of the language for new projects, especially when certain features are liable to change or become deprecated in favour of new approaches.
In fact, at the time of writing Apple have just announced Swift v1.2 with Xcode 6.3 beta.
With each release, the language and development environment become more stable and fully featured. Apple also appears to be listening to the demands of developers by fixing bugs and adding powerful features. The open source community have also been busy creating a wide range of useful libraries, frameworks and other utilities to make Swift development even easier (and fun). In addition, existing Objective C libraries may be used within a Swift project, reducing the upfront investment for new Swift projects.
Launching My Garage Tracker
At the time of writing, My Garage Tracker has just been approved by the App Store and is now available for download. Building My Garage Tracker was a great way to really get the hang of Swift development and I’m looking forward to using the language in new client projects.