SWIFT is a new programming language introduced by apple at WWDC 2014 for Cocoa and Cocoa Touch. The Cocoa and Cocoa Touch frameworks are the nuts and bolts that power OS X and iOS.
The language is much more concise. If you have a background in any C based language, you can easily work with this.
Why We Need SWIFT?
After introducing the Macintosh computer by Apple, Mac apps have been built using Objective C. Objective C is a programming language that was introduced in 1983. Objective C has evolved tremendously over the years, but certain features of the language have become outdated as the nature of the devices we use has shifted.
Back in 1983, we did not have smart phones so Objective C wasn’t developed with iPhones or touch interfaces in mind, and to compensate, Apple has built more and more new frameworks on top of Objective C. Instead of continuing to build frameworks on top of an older programming language, Apple introduced SWIFT.
The Five Key Swift Improves On Objective-C
In developer documentation, Apple highlights five key areas in which Swift over takes Objective-C.
Safe does not mean viruses protected safe mean Stable Wait hold on, have Ever had an iPhone app disappear with a black flash and end up back on your home screen? That’s a crash, and Swift is more stable than previous code, so that means fewer crashes on your iPhone, iPad, iPod, and other new iDevices
“Modern” means features which will be loved by developers but nothing for users. “Modern” also refers to new programming methods that have been popularised in recent years. Swift can accomplish more in a single line of code than Objective-C could in multiple lines of code.
“Powerful”, mean Intelligent. In Objective C, programmers have to include lots of Frameworks or Libraries to perform common tasks, because that core functionality wasn’t included within Objective C. Swift has many of those functions built in, so there is no need to pull in external files to get things done :)
“Interactive”, does not mean user Interactive with their device. it’s referring to the developer’s experience while coding. With Swift, developers see changes they make instantly rather than having to recompile a program every time they make a change. Its really cool :P
I will explain “Fast” in two ways.
1- “Fast” means code execution will be fast.
2- “Fast” also means that developers will have to do a lot of less work as compared to Objective C. Also developers with smaller budgets will now be able to develop apps/games that look and feel like the big-budget apps/games.
Technical point of view Here are some features of SWIFT that I note.
SWIFT supports classes which are key feature of OOP. SWIFT also supports single inheritance and also structs without inheritance.
Classes can have Properties. Properties have get and set methods like Objective C
Swift uses var, constants and types can be added optionally.
SWIFT supports operator overloading similar to c++.
A Range is an expression in the form 4…7 and can be used in control statements like if, switch, loops and also in array operations. Eg. replace element 4 to 7 with another element. The feature seems to be inspired by Python.
A tuple in the form of (code, message, <more elements>) can be used as a sort of a lightweight object.
Closures are basically lambda expressions that allow to inline code fragments.
The switch statement is quite powerful. It has no default fall through and is able to switch on a multitude of conditions like ranges, list of elements, boolean expression, enums etc.
SWIFT supports functions like any other language.
Protects from exceptions when calling multiple methods and properties in a chain where one call participant would return “nil”.