Early Impressions of WWDC 2015
Most of the headlines you’ve seen about WWDC this year — Swift going open source, iPad split screen, Apple Music, and Drake’s super weird moment on stage — have already been covered to death by all of the big tech blogs. Instead, let’s take a look at some of the smaller announcements and new features that will be exciting for people who spend their days inside of Xcode.
The more support Apple can give us with designing interfaces, the better. The brand new UIStackView class is a direct subclass of UIView that helps with managing other views in a row or column. According to Apple, UIStackView “leverages the power of Auto Layout,” which is awesome because Auto Layout is awesome. And best of all, the stack view creates and manages all the constraints for you.
UIStackView has a property called arrangedSubviews, which is an array of all the views it’s managing. The precise layout of the stack view is generated based on the values you give its properties, like axis, distribution, alignment, and spacing.
Of course, stack views work with storyboards. You can drag out either a vertical or horizontal stack view from the object library. You then drop in any views that you want the stack view to manage.
For more info, check out Apple’s awesome class reference for UIStackView.
Automatic User Interface Testing
Writing tests for your user interfaces sucks. Xcode 7 acknowledges this pain point, and offers something amazing: automatically generated interface tests via recordings. Xcode will capture your UI Actions and turn them into tests you can automate. In addition to this amazingness, Apple also made testing for Swift much easier. Instead of having to either make all your methods public, or adding your Swift source code files to your test target, you can now simply import your Swift files into your test files via the @testable keyword. Hooray!
Contacts and ContactsUI Frameworks
If you have ever written an app that needs access to the user’s contacts, you know how painful it is using Apple’s C-based API in your Objective-C code, and an absolute nightmare in your Swift Code. So, new with iOS 9, Apple has given us the Contacts and ContactsUI frameworks, designed to work easily with both Objective-C and Swift.
Most interesting, ContactsUI provides a class called CNContactPickerViewController, which is a view controller designed specifically for allowing the user to select one or more contacts from a list of their contacts. Best of all, the app does not need to ask permission for this access, since your app will only be able to touch the contacts the user selects, not their entire contact book. CNContactPickerViewController works with a delegate to manage selections, just like a table view.
Swift 2.0 Guard Statements
Guard statements is another new safety feature built into Swift that greatly increases the readability of your code. It does the same thing as an if statement, executing statements depending on the boolean value of an expression. However, a guard statement must have an else clause. The code inside of the else clause will execute if the condition being checked is not true. But this else clause has to follow special rules. It must transfer control to exit the code block that houses the original guard statement. It can do this with control transfer statements like return, break, or continue. It can also call other methods, as long as those methods don’t return.
The main benefit here is that the code block you want to fire off when the condition is false appears right next to that conditional check. And if the conditional check is true, the else clause is simply ignored. Also, any optional bindings you created as part of the conditional check are available to the rest of the code block! Pretty neat.
The Session I’m Most Looking Forward to Watching
Mysteries Of Auto Layout, Parts 1 & 2 — I’ve said it before and I’ll say it again: I can’t get enough of Auto Layout. And the more insider info I can get from Apple regarding this technology, the better. There seems to be two big additions to Auto Layout this year: The stack views I mentioned earlier, and the UILayoutGuide class.
The Session I Most Wished Was Happening
Mysteries of Core Data and iCloud — I’m a big fan of Core Data, and the ability to easily make it work with iCloud is awesome, when it works. There are still too many things going on under the hood that we developers need to be able to see or touch. Debugging with Core Data + iCloud is pretty much nonexistent. You just have to hope it works, which is a pretty bad way of programming things. Who knows, maybe Apple will sneak some improvements to this stuff into its CloudKit sessions.