For my first assignment at Floorplanner, I was asked to create an iOS application for Roomstyler to allow users to browse through existing designs and contests, place votes in existing competitions and get notifications of significant changes including changes to the contests and likes or comments on rooms the user has designed.
The preferred environment by Apple to design iOS apps is Xcode, it is available for free download in the App Store. Xcode contains the tools to build UI and code for the app, debug the app on both an iOS device or an iOS simulator and submit a build of the app to iTunes Connect.
Swift is a new language created by Apple to develop applications for desktop and mobile iOS devices. The language allows for writing short but still very readable code. Special care is taken in the handling of nil-able variables called unwrapping that makes it harder to accidentally forget required nil checks while at the same time allow short statements without a lot of ‘if x != nil’ cases as demonstrated in the code snippet below.
// get firstname of person, or nil if person is nil let firstname = person?.firstname // call method 'printData' on person if person is not nil person?.printData() // call method 'printData' on person and crash if person is nil person!.printData()
Swift is available for iOS 7 and higher. When an iOS version lower than that has to be supported, Swift is not an option. However, according to Apple, only 2% of iOS users are still using a version lower than iOS 7. Source: https://developer.apple.com/support/app-store/
The framework used to build the UI of an app is called UIKit. Although the UI can be created completely in code, most of the positioning of controls can also be managed using Interface Builder. The positioning of controls will most of the time be managed by defining different properties called constraints on controls. This allows building an interface that can automatically adapt to different screen sizes and orientations.
Adding logic to a UI element is done by assigning a delegate object (usually the view controller) to the UI element. This delegate will then be notified of all messages from that element that could be important for the app. Some controls (like a ListView) also have a data source property that works roughly in the same way to supply data to display in the control.
Downloading data from an HTTP/HTTPS server is pretty straightforward. Collect all the data to send as a request. When the server has responded another predefined method will get called asynchronously with the result data from the server.
Because it’s not supported to run UI specific code from any thread other than the main thread, the next step is usually to dispatch another method to the main thread of the app. This can easily be done by using the dispatch_async API method.
Manipulation of Strings is a little complex in Swift because all methods expect index types instead of an integer as positions as demonstrated in the example below.
let example = "Hello World!" // Does not work let o = example // Does work let index = example.startIndex.advancedBy(4) let o = example[index]
There are a few methods to share a preview of an iOS app with the team, The easiest of them is the TestFlight service provided by Apple through iTunes Connect. Initially setting up a new app in TestFlight takes a bit of work, as it requires to create an iTunes app record. However, as this is also required to release an app to the public it takes some time off the release as the record already has been created.
Whenever a new version of the app is to be shared with the team, the process of distributing the app is as simple as pressing a few buttons in Xcode. After being processed by Apple all team members will get a notification on their iOS device and can download and test the new version of the app by simply clicking the ‘upgrade’ button.
Submit the app
Releasing a version to the public is also pretty straightforward. The correct version that was released with TestFlight can be used to release on iTunes. After filling in some data about the app in the iTunes app record it can be submitted for review to Apple. The first 2 versions of the app have taken 7 and 5 days for Apple to review and accept. After Apple has accepted the app it can be released.
Since the first 2 versions of the app have been accepted on the first submit I do not have any experience with the process of re-submitting a denied version of an app.
Because Swift is still a young language, is still being refining a lot of the language. Unfortunately, this means that some versions of
swift it are not backward compatible. I have started the project in Swift 1.1 and when Apple released Swift 1.2 the project had to be converted. Now that Swift 2.0 is released the project has to be converted again to adopt the changes made to the language.
Although the changing language can be inconvenient, as converting the project takes time and old versions can no longer be compiled unless an old version of Xcode is used, the changes to improve the language and readability of the code. As the language matures we will probably see less breaking changes in new versions of Swift.
Although Swift now seems the preferred language by Apple, Objective-C is still very much alive and therefore have a basic knowledge about the language will still come in handy as over time a lot of libraries, as well as examples, have been written (and still are written) in this language.
Xcode allows mixing Swift and Objective-C code in the same project. I’ve used this to include a blur view library called ‘FXBlurView’ to the Roomstyler app. It has not been required yet to write any Objective-C code myself.