Swift 2.0-The smarter way to code
- June 18, 2015
- Posted by: Nimap Infotech
- Category: iOS
Swift 2.0-The smarter way to code
Apple also introduced the use of Swift which sent a mark of joy all over believing that there’s no need to learn objective C. But if you want to see yourself as an IOS developer than its becomes vital to know and make use of objective C. Actually speaking objective C is much easier than swift and once you are well versed with that language it comes just some time work to get hands on swift. C is a really easy little language, and Objective C is a simple little extension to C. Swift has numerous rules that Objective C does not have.
Swift has a bunch of constructs that Objective-C fail to have. For example, generics make type checking better in Swift, but it makes that language considerably more complex and messy.
At WWDC a new version of swift was introduced which is much faster, reliable, better performance, a new error handling API, and first-class support for availability checking. Swift 2.0 also includes the very new language features and more refinements.
Swift 2.0 feels acquainted to Objective-C developers. It adopts the readability of Objective-C’s named parameters and therefore the power of Objective-C’s dynamic object model. It provides seamless access to existing Cocoa frameworks and mix-and-match ability with Objective-C code. Building from this footing, Swift 2.0 introduces several new options and unifies the procedural and object-oriented parts of the language.
Swift 2.0 is friendly to new programmers. It’s the primary industrial-quality systems artificial language that’s as communicatory and pleasant as a scripting language. It supports playgrounds, AN innovative feature that enables programmers to experiment with Swift code and see the results directly, while not the overhead of building and running an app.
Features of the newly launched swift 2.0:
Sometimes things may go wrong. When a function fails, it’s always good to catch the error and understand why it fails. Swift version 1 lacked proper error handling model. In Swift 2, it comes with an exception-like model using try / throw / catch keywords.
The new error handling model in Swift 2.0 will instantly feel natural, with familiar try, throw, and catch keywords. Moreover, it was designed to work perfectly with the Apple SDKs and NSError. In fact, NSError conforms to a Swift’s ErrorType.
Using the latest SDKs makes sure you get access to new features and required data about platform changes. But sometimes you still need to target an older OS, and Swift makes doing so much easier and safer. The Swift compiler now generates an error when you use an API that is too new for your target OS, and #available blocks can safely wrap lines of code to only run when on the right OS versions.
No more println():
In Swift 2.0, we can only use print() to write something to the output. The new version of swift has combined both println() and print() functions into one. If you want to output something with a newline, you can set the append Newline parameter to true.
In the first version of Swift, you could use extensions to add new functionalities to an existing class, structure or enumeration. Swift 2.0 allows developers to apply extensions to protocol types. With Protocol Extensions, you can add functions or properties to all classes that conform to a certain protocol. This is useful when you want to extend the protocol’s functionality. Swift 2.0 now adds methods to common types so functions chain naturally, and your code is much more readable.
Do-while is now repeat-while:
The over the years used do-while loop is now renamed to repeat-while.
Swift 2.0 will also be made an open source soon. Swift is the way to go as it is the smartest and easiest way to code.