Swift 1.2 Arrives: 13 New Features

By | February 26, 2015
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

The worldwide iOS app development community is all abuzz with Swift 1.2 – which was launched in early-February. We have here highlighted the main features of interest in the new version of the language.

 

It took Google’s Go programming language well over 5 years since its release (in 2009), to feature among the top-20 coding languages. Apple, with Swift, has definitely stolen a march over its arch-rivals in this regard. Ever since getting the Gold Master (1.0) status in September, Swift has been riding on a crest of popularity among professional coders and iOS app developers. A recent Redmonk survey showed that the language had jumped an unprecedented 46 places in terms of popularity during the period between the third quarter of 2014 and January 2015 (the respective positions of Swift on the popularity list were 68 and 22). Earlier this month, a major update, Swift 1.2, was released along with Xcode 6.3 beta. Let us here take a look at some of the key new features of the latest iteration of Swift:

 

  1. Compiler diagnostics have become smarter - Chances of undetected errors and program bugs are minimal in Swift 1.2, thanks to the all-new Fix-it feature. Coders and developers would also get real-time error messages and warnings. This, in turn, will make program debugging on the go a whole lot easier. The final testing phase of Swift apps will become less complicated as well.
  2. Lesser warnings from SourceKit – Provided that the codes used by iOS/Mac developers are updated, SourceKit warnings generated from the Xcode editor will go down in Swift 1.2 drastically. Compiler crashes, a relatively frequent occurrence in the otherwise good earlier version of Swift, will become much, much rarer too. In essence, the new version of the Swift language makes the programming framework (Xcode) more efficient.
  3. The ‘Pyramid Of Doom’ has disappeared – Yep, we are talking about the multiple if-let coding architecture in the previous versions of the language. iPhone app development experts can now use multiple optionals for testing with a single if-let statement. Earlier on, it used to be a case of testing a single optional at one go, which tended to unnecessarily complicate the overall program. To avoid additional indentations, the new ‘where’ keyword (boolean inline) is very useful.
  4. Advantage of Incremental Build feature – Much to the delight of iOS developers, incremental build in Swift 1.2 lowers the build time considerably. The builds that are not changed are no longer auto recompiled by the new edition of the programming language. In case making a structural change in the program is necessary, the relevant files have to be re-created though.
  5. Easier downcasts with new keywords – While coding for apps with Swift, developers had to, till now, use the same keyword (‘as’) for both upcasts and downcasts. While there were hardly any room for error with the former – downcasts could become confusing, particularly if a coder did not have a clear idea of the class structure of the code. Swift 1.2 brings two keyword variations for making downcasts – the optional (‘as?’) and the forced (‘as!’). If you are a relative newbie on the Swift platform, go with the ‘as?’ keyword for optional binding.
  6. Using let constants will no longer be uncertain – Early adopters of the Swift language had highlighted the many complications that arose due to reassigning and/or changing let constants in any way, after they have been initialized. The latest version of the language does away with this problem altogether. General coders and mobile app developers have to mandatorily initialize every let constant (just as it is done with ‘var’). The constant can be used only after initialization. The reassigning option has been discontinued.
  7. Better semantics and Set data structure – Apple has given the erstwhile value semantics of Swift an overhaul as well. Users will now be able to take advantage of a whole new set of semantics, like Dictionary and Array. In addition, the functionality of NSSet has been bolstered with many new (unordered) elements. The overall native data structure in ‘Set’ has become more stable and powerful. There are no chances of duplicates getting stored in the Set struct. The only bone of concern is, stuff like NSDate are still missing.
  8. Swift 1.2 is swifter – Versions 1.0 and 1.1 of Swift were, contrary to the expectations of iOS developers, significantly slower than Objective-C (particularly during debugging, but also at the Build stage. Swift 1.2 more or less balances things out, and offers much higher coding and compiling speeds. The performance of the Release build has undergone a major upgrade, with several new optimizations coming in. The Debug build has also been boosted with binaries that are executable faster. In comparative terms, Swift is now (finally) more or less at par with Obj-C, and is getting better all the time.
  9. More stable compiler – This is a relatively minor change, but still, adds a lot to the overall stability factor of the Swift language. According to professionals who create iPhone/iPad apps, the re-engineered compiler of Swift 1.2 is a lot smoother, and is considerably less prone to bugs and crashes. During every stage of coding, the latest version of Swift offers greater runtime developer support.
  10. Exporting enums to Obj-C is easier – Although there have been rumors about the popularity of Objective-C stalling somewhat in last few months, Apple does not have any plans to phase it out (yet). Swift was always presented as a language that worked in collaboration with Obj.-C – and the new 1.2 version further highlights this. With the ‘@objc’ attribute, programmers and app developers can now seamlessly port enums from Swift to the Objective-C platform. For those learning to code with Swift, this comes in handy.
  11. New qualifiers for arguments and properties – App coders loved the option to message ‘nil’ in Objective-C, a feature that Swift does not have. However, the addition of new qualifiers for variables and arguments in the latest version of the programming language go a long way in making up for that. Null_unspecified, nonnull and nullable (only the last one can be set to nil) are the three qualifiers available to set the type of properties and arguments in a program. Developers who are not maintaining an Objective-C code can add these qualifiers to the Cocoa headers, for a more streamlined coding experience in Swift.
  12. More native Swift equivalents – Swift 1.2 makes it easier than ever before for iOS developers to cross over from Obj-C. It is pretty much clear that Apple is gradually opting for Swift implementations for most default classes in the older language. In Swift 1.2, it is no longer possible to automatically bridge classes like NSArray and NSString (in fact, any class in Obj-C that had a Swift equivalent). Unless the type conversion statement is explicit and includes the required native Swift equivalent, errors will be thrown up.
  13. Swift migrator for existing users of the language – An extremely handy feature of Swift 1.2 is the dedicated ‘Swift Migrator’. With it, codes for apps written in earlier versions of the language (1.0 and 1.1) can be ported to 1.2 with ease – and the effects checked out. Of course, both Swift 1.2 and Xcode 6.3 are in the beta-stage, and their final release is still a fair way away. Until Swift 1.2 gets Gold Master status, you cannot submit apps written in it to the store.

The latest version of Swift, with the Xcode 6.3 tool, can be used to create apps for Apple Watch, OS X Yosemite, and of course, the iOS 8.3 (beta 2 was released this week) platform. To check out previews of old codes in Swift 1.2, developers need to go to Edit → Convert → To Swift 1.2 (a target has to be selected to get the previews from Xcode). The adoption rate of Swift has already been impressive, and the new update has made the language smarter and even more developer-friendly.

 

Hussain Fakhruddin
Follow me

Hussain Fakhruddin

Hussain Fakhruddin is the founder/CEO of Teknowledge mobile apps company. He heads a large team of app developers, and has overseen the creation of nearly 600 applications. Apart from app development, his interests include reading, traveling and online blogging.
Hussain Fakhruddin
Follow me
 

Leave a Reply

Your email address will not be published. Required fields are marked *