It has nearly been 2 years since Swift launched. Many developers still face a dilemma when it comes to choosing between Swift and Objective C. If you are interested in learning iOS programming and making iPhone/iPad applications, the first step is to choose your development language, Objective-C or Swift. In June 2014, Apple announced their new programming language, Swift, at their annual Worldwide Developers Conference. It is a language which was created to make iOS development easier for beginners. Objective-C is often seen as a barrier to beginners because of its complex syntax. Let me explain that with an example, to initialize an array in Objective-C, you would write
NSMutableArray * array =[[NSMutableArray alloc] init];
But with Swift:
var array =[Int] ()
Objective-C has a very weird syntax with brackets and semi-colons. Swift is much cleaner with type safe similar to Python. It is powerful and intuitive programming language for iOS, OS X, and WatchOS. Writing Swift code is interactive and fun, the syntax is concise yet expressive, and apps run lightning-fast. Development is now like a popular mob. You have to go with the direction of the mob or you will be left behind holding just some theoretical arguments and little else. The community and of course Apple are now producing everything you need in SWIFT. There are only some elements which make up around 10% of a project that is not yet moved over, but in the next few months or probably a year they are most likely to move as well. More libraries and tools will be available for Swift since the community is inclining towards it.
Note: Today a relatively stable version of Swift (i.e. 2.1) is available in the market. That has sure caught attention of developers
BENEFITS OF USING SWIFT OVER OBJECTIVE C
- Faster in Process According to Apple’s release of Swift at WWDC, Swift is certainly faster than Objective-C for certain operations. For example, according to Apple’s analytics, Swift is a clear winner when it comes to complex sorting.
- Syntax / Variables declaration is easy in Swift It's much faster & cleaner to write. It'll be easier for others to pick up if they haven't worked with low-level languages like C. Optional are also really nice, because you either know an object can't be nil, or explicitly handle the possibility of being nil. Let’s take the example of string concatenation
Objective - C:
For example to assign text to a string requires a pointer to an NSString, one of the built-in types : NSString *abc= @“Hello this is”; abc = [NSString stringWithFormat:@“%@ ABC” , abc]; And that means you really need to know about pointers and memory allocation. Now the introduction of ARC (Automatic Reference Counting) simplified memory allocation as before that you had to do it manually, allocating it using retain and making sure it was freed up with release
No worrying about using a mutable or immutable string type, if you want a string you can change use var to declare it or use let for immutable. Concatenating strings is as easy as var abc = "My Name is " myStr += “ABC” What’s not so obvious that I didn’t even have to declare the string type. The compiler inferred it was a string from the right of the =.
- Swift is Interactive Swift Playground is an amazing tool for developers. It is an interactive Swift coding environment that evaluates each statement and displays results as updates are made, without the need to create a project.
DRAWBACKS OF USING SWIFT OVER OBJECTIVE-C
- Stability: Since Swift is a recently created programming language, there are still many bugs getting fixed by updates. After over 25 years in the market, you will come across less bugs in Objective-C than in Swift. This means that Objective-C is a more stable language compared to Swift.
- Maintenance of Code: Maintaining code is way easier in Objective C than Swift
- IDE Support: Swift has a poor third party IDE support. AppCode still doesn’t have code generating and on-the-fly analysis, not mentioning simple code completion.
- Trustworthy: Objective-C is from last 25 years in the market. So large amount of developer trust on this to create big / huge data application due to frameworks are bug-free.
HOW CAN YOU GET STARTED?
So if you’re ready to get started, what tools will you need? For either language, you’ll need a system that is running Mac OSX. The software used to code in Objective-C and Swift is called XCode. XCode is free and available to download in the App Store. If you want to start off with learning tutorials, check out AppCoda and Ray Wenderlich which both have Swift and Objective-C tutorials.
Originally published on Teamhunt.