Blogs

Best practices and trends in technology

Introduction To Apple New Language Swift

Apr 21, 2015
Image

INTRODUCTION TO APPLE’S NEW LANGUAGE – SWIFT !!

Swift is a multi-paradigm, compiled programming language developed by Apple for iOS and OS X development that has been introduced at Apple's developer conference WWDC 2014. This language is designed to replace Objective-C, while working with Cocoa, Cocoa Touch frameworks and existing Objective-C code so far written for various Apple products.

It is built with the LLVM compiler comprised in Xcode 6 beta, uses Objective-C runtime thus allowing Objective-C, Objective-C++ and Swift code to run within a single program.

Apple has now laid the foundation for Swift by advancing the infrastructure of the existing compiler, debugger and framework. The big idea behind Swift is that developers can write their code and see the results in real time; instead of writing line after line of code in a text box, then compile those results and wait to see the end result, as in the old paradigm. With Swift, developers can tweak an algorithm (or a parameter) and watch the changes happen right away in the same coding environment. Thus, letting developers to toy with concepts faster and make what they’re trying to make in lesser time.

Swift is anticipated to be more resilient against specious code due to the following notable features:

1. Swift does not create pointers and other unsafe accesses by default. It does not require header files as well. Moreover, the statements do not always need to end with a semicolon (';').

2. There is no need to use break statements in switch blocks. The individual cases do not fall through to the next case unless the fall through statement is used.

3. Variables and constants are always set and array bounds are always checked.

4. A dot-notation style and namespace system (which is more in common with other C-derived modern languages like Java or C#) has been replaced with the Objective –C’s Smalltalk - like syntax for making method calls.

5. A key portion of the Swift system is its ability to be neatly debugged and run within the development environment, using a read–eval–print loop (REPL).

Other musing and interesting features includes multiple return values, Generics, Type inference, Class-like structs, Trailing closures, Operator overloading. Swift is, in large part, a revisualization of the Objective-C language using modern concepts and syntax.

As the dust settled around the introduction of swift language, Mac and iOS developers still have a plenty to ponder and explore, though many have also come up to Swift after voicing early concerns. Swift got a full-throated roar of appreciation from the thousands of developers as it solves the major concern that a panel of iOS and Mac OS X developers had with using Swift in actual production code specifying that even if the language is still under development today, the apps will not break in the future. For instance; if a Swift app is written today and submitted to the App Store, then not only the app will work well into the future with iOS 8 and OS X Yosemite release, rather can target back to OS X Mavericks or iOS 7 with that same app as well. It is possible since the Xcode embeds a small Swift runtime library within the app’s bundle and since the library is embedded, the application uses a reliable version of Swift that runs on past, present and future OS releases.

Lastly, it’s understood that instead of a developing a powerful new language, Apple has actually tried to develop a popular one. Swift no doubt has a lot of features that may seem alien to someone coming from Objective-C, but they eventually make a lot of sense and will be nice to use. For now, we are in the earliest days of the transition from Objective-C to Swift and there will continue to be naysayers.

About Author