Another year, another new version of iOS–and with it comes a brand new version of Xcode. They say a worker is only as good as his tools, and so it is reassuring to know that Xcode 6 has added a slew of new features to make life as an iOS developer easier and faster than ever.
Adding New Files
One of the most frequently used dialogs in Xcode has been given a bit of a facelift.
- –New file types have been added for Swift. Specifically, a Swift file empty template and a Playground file which allows for dynamic debugging as you code.
- –Objective-C File is now a category for a bunch of Objective-C file types including Category, Protocol, and Extension. There is also an “Empty File” option which creates a regular .m file without a header.
Storyboards with Size Classes
The release of iPhone 6 / iPhone 6+ means we iOS developers finally get to deal with the wonderful world of fragmentation! One thing that will make lives easier is the introduction of size classes for design instead of defaulting to separate iPhone / iPad view files. Size classes allow you to use only one storyboard per view controller instead of having multiple views and deciding the right one at run time. Further, you are able to add UI elements that are specific to certain views, so you can have, for example, custom iPad elements that are not seen on iPhone and vice versa. It’s also possible to set constraints for each view differently for each size class, allowing for really simple UI design across a multitude of devices.
You can enable size classes in the same way that you enable Auto Layout in a storyboard file, and in Xcode 6, size classes are enabled by default when you create a new storyboard file. Most sizes are compatible with iOS 7, but be aware that Compact Width, Compact Height and Any Width, Compact Height are not respected in iOS 7.
Application Launch Screens
LaunchScreen.xib is a new way to handle launch images. This allows us to use Interface Builder to create launch screens instead of relying on using multiple image files for each orientation and size. We can simply use Auto Layout to control how those items will look while only needing to create one design for launch. The old LaunchImage folder is still supported, but all new projects default to the .XIB approach.
The simulator menu now has options for all of the device types supported by iOS 8, as well as two new options: Resizable iPhone and Resizable iPad. These simulators are coupled with size classes, allowing you to test the various iPhone and iPad sizes in one simulator instead of having to constantly reboot the simulator or rebuild your project to debug the views.
Auto Layout Margins
Auto Layout now supports default margins for leading / trailing space. This means that there are now 16 pixels of built-in space between the edge of the screen and the margin. This means a leading space of 0 puts an item 16 pixels away from the edge. This is only supported in iOS 8+, however; iOS 7 does not support this, and Xcode will throw a bunch of warnings to alert you to this, so be careful if your app supports iOS 7.
You can now debug your views. By going through the debugger, you can pause execution of the application and Xcode 6 will display your view as it exists at that moment in time. You will see all views – even views that are currently not visible. This allows for very rapid debugging of Auto Layout at runtime, instead of having to guess and check by rebuilding the application every time. By going to the Attributes Inspector in the view debugger, you can look at all of the Auto Layout attributes that are applied to each element, which attributes are active, and even which attributes were ignored or not used by the application.
Live View Rendering
Now you can have a live rendering of a view in a storyboard as you edit it in a text editor by using IB_DESIGNABLE. Now edits that are made in drawInRect will be rendered live in the View. You can now also specify IBINSPECTABLE attributes to property values that you want to be assigned in the storyboard file. This allow for enhancing storyboard functionality by being able to see your custom controls rendered on the storyboard itself instead of just a placeholder white box where the control would appear at run time.
The latest version of Xcode really adds some great and much-needed features to the iOS developer’s toolbox. View Debugging and Size Classes are the two most useful and long overdue features that will almost assuredly be the most used features in this last release. iOS as a platform has grown quite a bit with version 8 and the release of the iPhone 6 and iPhone 6 Plus; the newest features of Xcode 6 make this transition considerably easier and more seamless.