Why I Choose Swift Over Objective-C For IOS Development?

Written by srimanikanta | Published 2019/02/18
Tech Story Tags: ios-app-development | objective-c | swift | mobile-app-development | swift-programming

TLDRvia the TL;DR App

The path for IOS Development is pretty simple and straight forward with Swift.

When I started learning IOS development, I chose Objective-C as my core programming language. During my journey, I faced a lot of struggles with Objective-C because it is one of the toughest languages I had ever come across. It was a nightmare for me to develop apps with the help of Objective-C. The syntax of Objective-C is not very programmer friendly so it became very difficult for me to write and debug the code. Most of the beginners would also have the same problem with IOS development but when it comes to Android development things are very easy and it is like a cake walk because JAVA is much better than Objective-C to code.

When I started my journey, Swift was already a booming thing in the market. Since Objective-C was an old programming language I thought that it had good resources and community to learn from. StackOverflow has a good community for Objective-C to deal with bugs and issues. For those reasons I chose Objective-C. Even though the resources and community are good, things were not happening in the way I wanted. So in the end, I got fed up with Objective-C and made a decision to change my core programming language to Swift because of some big reasons —

As a Swift Programmer (Currently addicted to it 😍) I love to code in swift rather than Objective-C to build an IOS App from scratch. Because I found out that swift is more flexible than Objective-C. Swift was officially released in the year 2014 by Apple INC. Until 2014 IOS developers usually worked with Objective-C, an object-oriented superset of the C programming language that has been the core part for IOS development so far. But things are changed from 2014 because swift was introduced as a new programming language for IOS development that’s given IOS developers an alternative to choose Swift.

Developers and programmers developed swift programming language with good syntactic sugar that employs modern programming language theory concepts and strives to present a simpler syntax. It is compatible with all of the existing IOS development tools like — XCode, Cocoa framework and many more. But it’s ease of use and improved features has helped swift to quickly replace Objective-C. It’s designed to give developers more freedom than ever. This feature helps most of the beginners and developers to learn and develop new things quickly and easily.

In this article, we’ll explore a few reasons about why you should get started with the Swift programming language for your next iOS app development project if you haven’t already. You might already be an IOS developer with Objective-C background but we need to adopt the new changes quickly if they are good enough.

The Quicker You Let Go Of Old Cheese, The Sooner You Can Enjoy New Cheese.

— Dr. Spencer Johnson.

The reasons for changing my core programming language to swift —

Simplicity

Photo by rawpixel on Unsplash

Swift programming closely resembles natural English because of its good syntactic sugar. This readability makes it easier for existing programmers from JavaScript, Java, Python, R, and C++ to adopt Swift into their programming belt. Swift requires less code to perform the particular task but when it comes to Objective-C we need to write a verbose code to perform that same particular task. Debugging is also pretty straight forward in Swift than Objective-C.

Photo by Gustas Brazaitis on Unsplash

Swift removed pointers concept which improved the security and robustness of the programming language. As Objective-C is an old programming language, it has pointers concept like — C, C++ programming languages. The reason behind removing the pointers concept in swift is that pointers allow a great vulnerability towards our application for the Hackers. So all modern programming languages like — Java, Python, JavaScript, Kotlin etc. removed pointer concept in their language implementation.

Speed

Photo by chuttersnap on Unsplash

When it comes to speed and performance, Swift is on the upper hand because it runs faster. According to Apple.inc, Swift is 2.6x faster than Objective-C and 8.4x faster than Python.

Maintainance

The file management of Objective-C is really an irritating process because we need to manage two separate files in Objective-C. Since Objective-C was created from C and it depends on C programming when it comes to changes and improvements. We have to maintain two separate files of code in order to improve the efficiency and the developing time of an application.

To fix this issue Swift came up with LLVM (Low-Level Virtual Machine) to figure out the requirements and automatically complete the incremental builds.

Dynamic Library Support

Photo by Iñaki del Olmo on Unsplash

One of the biggest change in Swift is to switch from static libraries to dynamic libraries. Dynamic libraries help us to execute a chunk of code that can be linked to an app. The difference between dynamic libraries and static libraries is that dynamic libraries can be linked to any program during run-time.

Static Library

Static libraries are linked at the last step of the compilation process after the program is placed in memory. As a result, the executable file must be recompiled in case any changes were applied to external files. Static libraries are also updated along with other updates like a new OS version.

Dynamic Library

Dynamic libraries are automatically included in the AppStore’s download package. The shared code is loaded once and can be used by a large number of programs. This code can be updated, changed or recompiled without recompiling the application that uses this library. Dynamic libraries are external to the app executable but they can include within the app bundle downloaded from the App Store. Dynamic libraries can update pieces of code directly in an app. It reduces the initial size of an app as it is loaded into memory since the external code is linked only when it is used. These libraries are not supported until IOS 8.

Swift Playground

Playground — Noun: A place where people can play.

Photo by Jeffrey Lin on Unsplash

Swift Playgrounds are very much helpful for the new programmers and developers as well. because it provides a very interactive environment to test our piece of code without running our whole application. It is one of the great features of IOS which is not available in android.

Most of the people argue that playgrounds are not for beginners, but I feel it is very much helpful for developers. When I started my journey to learn IOS development, my first program was written in the playground and it also helped me a lot to learn swift programming language quickly. However, while developing my apps to test any logic or piece of code, I always use the playground to do my task.

Swift comes with good memory management scheme over Objective-C because In Swift we don’t need to bother about managing memory because of ARC (Automatic reference counting) which automatically frees up the memory used by class instances which are no longer needed. Swift handles most of the memory management of your apps and allocates or deallocates memory on your behalf.

But when it comes to Objective-C, it has two types of memory management techniques —

  1. Manual Retain Release. (MRR)
  2. Automatic reference counting. (ARC)

In MRR, we need to manage the memory explicitly by keeping track of objects on our own. This is implemented using a model, known as reference counting. The only difference between MRR and ARC is that the retain and release is handled by us manually at present while its automatically taken care of later. In MRR we need to follow several rules to manage the memory which is really a nightmare for the programmer.

Even though Objective-C has ARC Memory management mechanism, ARC is supported only within the Cocoa API. ARC does not provide support for Graphics APIs. Developers need to work hard to manage such things. To solve this problem Swift enhanced the memory management to support across all APIs, this enhancement helped most of the developers and programmers to spend less time on memory management.

Those are the reasons which addicted me to change my core IOS Development environment to swift programming language from Objective-C.

Conclusion

Since Swift has many advantages over Objective-C and it is developed to give more freedom for developers, I changed my choice from Objective-C to Swift. After changing my language from Objective-C to Swift my development life became more simple and comfortable. That’s the reason why I love swift 😍more than Objective-C.

If you didn’t try Swift you are really missing out a wonderful journey in your development career. That doesn’t mean Objective-C is not good for IOS development or it is going to die because for both the languages Apple is providing good support. But Swift is rapidly growing than Objective-C.

If you have any experiences or any other information to share regarding this topic feel free to comment.

Thanks for reading my article by killing your valuable time, I hope this article helped you to learn something new.

If you liked this article please click on the clap and leave me your valuable feedback.


Written by srimanikanta | Problem Solver || Started Journey as a Programmer || Techie Guy || Bibliophile || Love to write blog
Published by HackerNoon on 2019/02/18