It is that time of the year again! Eyes glued to the monitor (or the stage), everyone interested in the Apple world is eagerly awaiting the launch of the new iPhone. It’s a 7! (And the 7 plus!) The audience is ecstatic, but there is a group that might be a little bit worried – developers. The launch of the iPhone 7 also means that the public release of Swift 3.0 and iOS 10 is around the corner.
Swift 3.0 is the latest and greatest version of Swift that will be bundled with XCode 8 and the resultant binaries will, sadly not be compatible with prior versions. Swift 3.0 promises to change pretty much everything on the development scene and is a cause of worry for many developers whose applications will fail to build unless they make the required changes.
iOS 10 has also proposed a slew of new features and changes along with its announcement. With improved Maps with navigation support built in to a redesign of Apple Music, snazzier Messaging and predictive type takeover by bringing Siri intelligence to QuickType and use deep learning to allow better and more intelligent predictive typing using expanded contexts.
As Swift 3 is the last release to make major code breaking changes, it is also the release that re-evaluates syntax and semantics of the core of the language. This means that many obscure or problematic features will be removed, and the focus will be on improving the consistency of syntax in many ways, no matter how minute, and focus on futuristic improvements to the type system. This will serve the overall goal of making Swift a simpler, more predictable, and more consistent language over the long term.
As Swift 3 will be the primary development language supported by Xcode 8, so developers need to decide if they wish to continue using Swift 2.3 or switch to 3.0. First, Swift 2.3 and Swift 3 are NOT binary compatible so your app’s entire code base needs to pick either version. As both versions are fully supported by the compiler, SDKs, and debugger, developers can choose either but they also need to keep in mind that some features of the IDE may not work with Swift 2.3. For example, Playgrounds will only work with Swift 3, and the Swift Playgrounds app for iPad also requires Swift 3. All Xcode project templates use Swift 3, and all documentation will be available in a format appropriate for Swift 3.
Apps relying on notifications need to be updated as iOS 10 made a lot of changes around notifications, creating new ways developers to handle incoming user notifications. Specifically, notifications are now handled by methods belonging to the UNUserNotificationCenterDelegate protocol, while the old UIApplicationDelegate methods like application:didReceiveRemoteNotification are now deprecated.
When converting to Swift 3, developers will notice that nearly every file needs changes, as all the Cocoa API names have changed. To be precise, the API is the same, but there’s one name appropriate for Objective-C and one name appropriate for Swift. Swift 3 is going to make Swift much more natural to write henceforth. Apple has included a Migration Assistant with Xcode 8 that can make most of these changes in one go. Some areas might still need to be touched up that the migrator does not automatically handle. Developers can now convert to either Swift 2.3 or Swift 3. If there is ever a need to bring it back up, they can navigate to Xcode to Edit > Convert > To Current Swift Syntax…. The compiler actually shares the same intelligence as the Migration Assistant as well. If the old API is accidentally used on a method call, the compiler will offer an option that will help you use the correct modern API.
The best news of all is that Swift 3 aims to be the last release with breaking source changes. So going further, developers should be able to keep their Swift code from version to version. While the core team can’t predict the future, they have promised that if they do need to break source compatibility, they will offer long deprecation cycles. The biggest update in Swift 3 involves the standard library adopting consistent naming conventions. The API Design Guidelines contain rules that the API Devs settled on as they built Swift 3, which placed a high value on readability and accessibility to new programmers. The core team operated on the principal that “Good API design always considers the call site”. They strove to bring clarity to the point of use.
As far as old API handouts are concerned, GCD and Core Graphics have both received a much-needed makeover. UpperCamelCase is now reserved solely for names of types and protocols. While this may take some getting used to, it is good for maintaining consistency. The standard library is also getting more consistent in method naming with verbs and nouns. You can select a name based on the side effects or the actions taken. The rule of thumb is that if it includes a suffix like “-ed” or “-ing” then think of the method as a noun. A noun method returns a value. If it doesn’t have the suffix, then it is most likely an imperative verb. These “verb” methods perform the action on referenced memory. This is also known as modifying in place.
Swift is a language, and a large part of writing it involves using a development environment – which for Apple developers is likely Xcode! The changes going on with the tooling will impact how you write Swift every day. Swift 3 fixes bugs in the compiler and IDE. It also improves the precision of error and warning messages. And as you might expect, with each release, Swift is getting faster in how it runs and compiles by improving string hashing. Moving objects from the heap to the stack resulted in a 24x speedup in some cases. The compiler can now cache multiple files at once (when doing whole module optimization). Code size optimization has reduced the compiled size of Swift code. Apple’s demo Demobots reduced the compiled size to 77% of the original. This has helped apps become faster while having a much smaller footprint.
iOS developers now face an added (and maybe daunting) task and the dilemma of making the switch from Swift 2.x to 3 (or not) and revamping their source code to use all the functionality available in Swift 3.0 which might be a gargantuan effort in some cases. This also makes it difficult for testing teams as their automated testing tools might be calling deprecated methods, all of which needs to be updated, however, all of this might be fruitful in the end as with the new iPhone comes an increased user base that is constantly on the lookout for new features, apps with a smaller footprint giving them to install more and more in the same space and, of course, Stability. Swift 3.0 might take a little getting used to and frustrating for developers but change has never been easy. This, however promises to be a change that has been for the better.
Apple accepted that it’s market has matured to a point where bringing the Wow factor to each release isn’t on the cards. The highlights for this release were the Air Pods which finally free the user of the wires, which brings us to the case of the vanishing 3.5 mm audio jack. The Air Pods will connect to a wire that plugs into the lighting port for connectivity. The iPhone 7 boasts of dual cameras that give you an optic zoom reaching quite close to what a DSLR has to offer. With a better battery life and better hardware Apple has high expectations from it’s new product and all the Apple fans are already trying to get their pre bookings sorted. The Apple mania has taken over and it’ll be a while till it wears off.