Swift is a new programming language for iOS, MacOS, watchOS, and tvOS apps that build on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Swift’s clean slate, backed by the mature and much-loved Cocoa and Cocoa Touch frameworks, is an opportunity to re-imagine how software development works.
Swift feels familiar to Objective-C developers. It adopts the readability of Objective-C’s named parameters and the power of Objective-C’s dynamic object model. It provides seamless access to existing Cocoa frameworks and mix-and-match interoperability with Objective-C code. Building from this common ground, Swift introduces many new features and unifies the procedural and object-oriented portions of the language.
What Changes the Swift will bring to IOS Development
- Swift will result in better apps for the Mac, iPhone and iPad user.
- Swift makes it easier than the current language to write, test and launch great Apple apps.
- Apps will be more fun, more useful, more robust, less buggy and more complex.
- Swift will work with and replace the 30+ year old Objective-C, Apple’s current app programming language.
- Swift is faster to code and easier to test than Objective-C.
- Swift code can often run faster than Objective-C and other languages, like Python
- Less verbose (a lot)
- Drop the semicolons at the end of statements
- “Natural” parenthesis, i.e., a lot fewer than before
- More “natural” and modern language
- Almost no manual memory handling required *
COMPARISON WITH OBJECTIVE C
Objective-C is a pure superset of C. It supports C syntax, plus object-oriented extensions. The syntax is a little bit contorted as a result. Objective-C is also pretty tightly coupled to the Apple Foundation classes on which it was developed. Every class in Objective-C is based on the NSObject base class, which is a Foundation class.
Swift is a more modern language. It is not a superset of C, so the creators were able to make the syntax and the semantics cleaner and more coherent. Swift can inter-operate with Objective-C, and a number of Swift classes (e.g. scalar types, arrays, dictionaries) are interchangeable with their Objective-C (NSObject based) equivalents, but Swift is not coupled to those classes.
- Swift supports a limited operator overloading. Objective-C does not.
- Many things like structs, enums, and scalar types are first-class objects in Swift that are not objects in Objective-C
- Swift offers many concepts and features of functional languages like Haskell.
- Swift supports Tuples. Objective-C does not.
- The switch statement in Swift is incredibly versatile and powerful. Objective-C’s switch statement is the same as C’s, and is very limited in comparison.
Observing our favorite Objective-C and fresher’s favorite Swift, we might not be able to find a big difference. Objective C, which has been in the field since the very beginning of iOS, holds much importance and is quite popular. Simpler Syntax and easy to understand features makes it user-friendly. It is valuable and good but it still lacks some of the features that developers always wanted, just like the Tuple feature introduced in Swift. As per my experience working on both the technologies, it is one of the best features in Swift. Removal of ’NS’ from Arrays, Dictionaries makes Swift provide comprehensible codes and give a much neater look, providing much more readability.
Transition from Objective-C to Swift
To make the transition from Objective-C to Swift a smooth process, Apple made the syntax similar and more familiar. It removed some of the prefixes and added some suffixes to the existing ones. Features like providing the range for iterative statements, switch functionality revamp, type inference, closures, which are similar to blocks, generics, which can take up any data type, are some of the beneficial ones in Swift. And on the applications side, the change that Swift has brought in is the 1 or 2 lines of code in Swift compared to lengthier code in Objective C. Swift supports Unicode characters, as variable names, which Objective-C does not.
Apple considers Swift as a safe, modern and powerful coding language. Playground feature, which is present in Swift, allows the user to interact with a running application, side by side, which Objective-C cannot. Swift, being a bit high on the graph, claims to provide a better performance.
- Swift has a lot of cool things, such as safe memory management, strong typing, generics and optional, simple but strict inheritance rules.
- Swift is cleaner and more readable than Objective-C. There are modules that eliminate class prefixes. It also has half as many files in a project and understandable closure syntax.
- Swift allows to create flexible and lightweight classes which contain exactly what you want (no root class), i.e. if you want to print description, just implement the protocolPrintable and if you want to compare – implement Comparable.
- Swift isn’t that fast but isn’t slower than Objective-C either.
It’s high time to make the switch to the more approachable, full-featured Swift for iOS and OS X app development. The language has optimized for performance and makes easier for App development. Swift is probably your best bet for general applications now. However, there are still going to be times when it’s useful to have very fine-grained control over things, at which point a working knowledge of C and Objective-C will stand you in good stead.