Shift to SWIFT: An Unusual Journey from Objective C

Shift to SWIFT: An Unusual Journey from Objective C

Apple has come up with its new programming language ‘SWIFT’ after having used Objective C as its programming language for a long long time.

Change happens for a reason and when things move in the magnanimous empire of Apple, people listen. People wonder. People question. The question here isn’t whether or not SWIFT is better than Objective C, but the question is ‘Why shift to a relatively new language SWIFT when you were already successful with one of the most powerful, robust and a proven language- Objective C?’

I personally believe that someone like Apple would not go for such a change unless it is absolutely necessary. I have faith in them which is why this blog is not going for a ghost-hunt. Let’s see what we can find out and whether there are legitimate reasons to blindside Objective C for SWIFT.

“The SWIFT code is much more precise and approachable. SWIFT gives more independence and empowers application developers logically as much visually”

A quick glance at the content of this blog:

  • The advent of Objective C,
  • The value of Objective C in mobile application development arena,
  • How & why SWIFT came into existence,
  • The capabilities and benefits of SWIFT, and what indeed was the reason of this ‘shift’
  • A quick comparison Objective C vs SWIFT
  • The answer to this mystery of shift to SWIFT

 

The Objective behind ‘Objective C’: History

Apple opened its App Store in the year 2008 and since then a revolution has begun which has led to the most vibrant of mobile apps ecosystem in existence. Objective- C is used by application developers to build apps on iOS and OS X. It should be known that Objective-C has now become the third most popular languages after C and Java.

But this is where Objective C has reached. To learn how and why SWIFT has been adopted, application developers probably need to check out the times when Objective C was being adopted. So let’s go back in time and have a quick glance of what happened then?

Objective-C was created at the Stepstone company in the early 1980s by Brad Cox and Tom Love. In late 1980s it was licensed by NeXT Computer Inc. to develop the NeXTSTEP frameworks that preceded Cocoa.

In 90’s Apple got merged with NeXT and using NeXT’s operating system, NeXTSTEP, Mac OS X came into existence. Mac OS X’s Cocoa was adapted into the iPhone OS which came into existence from NeXTSTEP’s application frameworks. Cocoa Touch emerged from Cocoa later on.

Apple chose Objective-C as it was already the language of NeXT. Steve Jobs incorporated Objective-C which became the backbone of OS X and iOS in years later.

Reasons why Objective C was adopted

The question at this point was this:

“If the giants were C, C++ etc, why did Apple decide to go for Objective-C to be used as the programming language for iPhone SDK instead?”

My research on this gave me lots of interesting opinions.

Speaking in the application developer’s communities and forums, their speculations went along the lines of “… they probably were looking to take control of this low-level language so that they can merge it with OOP concepts and that should help them better collaborate with the object-oriented features. They will also be able to customize it with system libraries…”

Many people who are associated with the brand name of Apple claimed that when Jobs founded NeXT Computer in 1985, he brought some of his former Apple team members and application development programmers who were interested in doing the expansion on C so that they can avail speedy benefits and system control.

Few critics said ‘Obj-C is as much a syntax styling language as much a smart programming language – one can benefit from the same as it offers amazing power to Mac, iPhone, iPad.’

At this point, let’s not reject or accept any of the reasons yet and get into the technical aspects of embracing Objective C:

  • First, it is an object oriented language. The kind of functionality which is packaged in Cocoa frameworks can only be delivered through object-oriented techniques which can be incorporated with Objective-C.
  • As Objective-C incorporates C, you get all the benefits of C when you work with Objective-C.
  • Fundamentally simpler. Its syntax is small, unambiguous and easy to learn.
  • As steep learning curve for new recruits as it emphasizes on abstract design.
  • Well-organized language which result in more proficient object-oriented programmer.

The points do seem convincing enough and for years Apple’s marriage with Objective C lived in harmony.

Until of course there supposedly arose a need to move on to a different language..

“Change is the law of life”
John F. Kennedy

 

Shift to SWIFT – The need for something new

In the past, Apple has employed many leading creative designers and innovative coders whose efforts are obvious to us via the implementations of languages such as JavaScript, Python, WebKit and Ruby. Apple has been capable of developing apps using third party systems based on other languages while also being keen to develop the best of tools possible. Apple was expected to benefit by having their own language customized and optimized exclusively for Cocoa Touch and Cocoa development. It was common observation that with bulk modifications and loop configurations there were regular code repetition errors which developers had to face.

“By bringing into play just few new elements SWIFT allows you to reduce overheads for app building”.
Mr. Maninder Bains

 

The Announcement

It was a huge surprise at WorldWide Developers Conference (WWDC) when Apple announced building a new programming language for iOS and OS X called SWIFT.

Company explained that the new language – which is in beta until iOS 8 – will indeed be Apple’s replacement for Objective-C. SWIFT’s inception when announced by Craig Federighi was welcomed with a ‘whoa’ feeling thronged with applause and appreciations.

Company Reasons out:

Apple claims that we can expect huge shift in the way iOS and Mac apps will perform in the coming years. Some highlights of their opinions after the announcement of SWIFT:

  • It is fast. It supports many modern programming conventions including type inferences, generics, multiple return types and more.
  • It is a more ‘modern’ option which takes features from languages like JavaScript and infuses within “power of Objective-C without the C”. This gives app developers a new level of interactivity on the iOS platform which therefore makes SWIFT a robust development tool for developing social networking apps and intuitive 3D games.
  • They also added since SWIFT has been in development phase since many years, it will be easy to adopt for new app development experts instead of the veteran developers.
    • Apple wanted new mobile app developers to approach their platform with ease and comfort and therefore could raise with safety and stability.
    • App quality and safety was Apple’s main concern which SWIFT compliments.
    • SWIFT is like a scripting language which incorporated the elements of OOP and functional programming therefore it brings developers from other fields. Those having expertise in Javascript, Python and Ruby can use this language as much.

Technical Advantages:

SWIFT has been the result of researching programming languages, combining decades of experience. It has certain fabulous features an application developer can actually fall in love with since it makes your code more expressive. Check these out:

1. Clean syntax that makes APIs in SWIFT even easier to read and maintain.
2. Application programming interfaces (APIs) in SWIFT are simple to read.
3. SWIFT manages memory automatically and you are not required to type semicolons.
4. Just like many scripting languages, the compiler in SWIFT gathers the variable type, such is not the case with Objective C which relies on defined pointers.
5. Closures unified with function pointers.
6. Tuples and multiple return values.
7. Fast and concise iteration over a range or collection.
8. Structures that support methods, extensions, protocols.
9. Functional programming patterns Eg. map and filter.

Power of SWIFT and Its Distinctiveness

Power of SWIFT
1. Designed for Ensuring Safety: SWIFT eliminates entire classes of unsafe code. The variables in SWIFT are always initialized before use. The arrays and integers are checked for overflow, and memory is managed automatically. Understanding and properly handling cases where objects are nil is fundamental to the frameworks, and SWIFT code makes this extremely easy.

2. Intuitive and Interactive Playgrounds: I personally feel that it is of critical importance to have quick visual of how an algorithm works. ‘Playgrounds’ is certainly a big help for game developers. Playgrounds make writing a SWIFT code simple and fun. You just have to type a line of code and the result appears immediately. You can watch the progress of your code in the timeline assistant. Watch the display variables in the graph, keep drawing while composing view and you can play an animated SpriteKit scene and when you have coded perfectly move the code into your project. Using playgrounds you can experiment new APIs which can hone your SWIFT coding skills. Verify your new tests before actually promoting into your test suite. Watch the your designed algorithm on each step.

3. Fast and Robust: I have been repeatedly saying that ever since its inception SWIFT has been built to be fast. The syntax and standard library are tuned to make the most obvious way to write the code which performs at its best. Since it is the successor of C and Objective-C languages it includes primitives such as types, flow-control, operators and fosters object-oriented features such as classes, generics, protocols therefore, giving Cocoa, Cocoa Touch developers the power the demand.

Benefits of SWIFT for Businesses and Developers:

1. Programming: SWIFT is not very much complex therefore does not require much parallel programming. It can run number of programs simultaneously.

2. Swift, smooth and Speedy: Business can be big and big businesses operate around thousands of lines of codes for simplest of functions for state-of-the-art optimizations. You can launch millions of programs together and hundreds of programs per second in SWIFT. You can work on large scale and simple and short scripts. You can run same script on supercomputer, grids, clusters and cloud.

3. Flexibility: It is such a beautiful programming language that its extensive features can be used in varied domains which includes engineering and science, education, physical sciences, biological sciences, humanities and social sciences.

SWIFT coding seems exciting

I suppose my blog would have given you as a blogger, developer, programmer or a researcher sufficient information about the transition from Objective C to SWIFT. The blog suffices the changeover and makeover of programming languages and how SWIFT language is playing a vital role.

All the best with using Swift!

Bye Bye Objective C?

Still there are possibilities to mix the code in SWIFT with Objective C while retaining compatibility. It is likely that SWIFT will be subjected to some non-compatibility changes in syntax. SWIFT on the contrary has number of capabilities of the Objective C/C++/C environment.

You might have to create some libraries in Objective C if you want to write a code in SWIFT. It is no doubt that SWIFT is providing better ways of doing what you could have done in Objective C.

There are significant parts of CoCoa which depend on Objective C. Just as C is based on assembly and Objective C is based on C, SWIFT is based on Objective C.

Objective C and SWIFT are interoperable and application developers can develop apps in SWIFT using third party libraries to build software for iOS7 and iOS8. You can also mix and match languages, even within the same library.

In the short run, it seems they will be used interchangeably but in the longer run, I don’t see a reason why they should co-exist. Bye Bye Objective C indeed but not just yet. Not yet.

Quick Comparative Analysis of Objective C vs SWIFT:

S.No SWIFT Programming Language Objective C
1 The syntax in SWIFT is clear and concise therefore makes APIs in SWIFT easier to read and maintain. SWIFT also maintains compatibility and interoperability with a number of C language types and features. Programming language, Objective-C is based on C language, which is difficult to master on its own.
2 SWIFT takes features from various other programming languages like JavaScript and also infuses the power Objective-C.
This gives application developers a new level of interactivity on the iOS platform which therefore makes SWIFT a robust development tool for developing social networking apps and intuitive 3D games.
The approach that Objective C takes to passing messages between applications or within an application is difficult to learn.
3 SWIFT is great programming language for people interested in developing for iOS/OS X. SWIFT’s syntax is much more concise and friendly, probably inspired with the likes of languages like Python, Ruby, and Rust. Objective-C is a notoriously difficult language since its syntax is unlike that of any other major programming language. Still some unambiguous syntax as compared to other programming language.
4 SWIFT allows you to develop your app interactively. Objective C does not allow you to develop your app interactively.
5 SWIFT has type inference. Objective C does not have type inferences.
6 SWIFT has generics. Objective C does not have generics.
7 SWIFT is incredibly expressive programming language. Objective C is not as intuitive and expressive as that of SWIFT.
8 SWIFT brings within itself better type safety, better memory management, multiple return values, and a bunch of functional paradigms. Programming language Objective C is not as safe as that of SWIFT.
9 You cannot subclass a Swift class in Objective-C. Classes can have subclasses in Objective C.
10 Command-click a Swift class name to see its generated header. No such feature in Objective C.
11 Option-click a symbol to see implicit information about it, like its type, attributes, and documentation comments. No such feature in Objective C.
12 It’s not necessary to end statements with a semicolon in Swift. In Objective-C, it’s necessary to put a semicolon at the end of a statement..
13 Switch statements must include a default statement. Programmers must include brace brackets to open and close “If” statements, which prevents bugs such as the SSL “goto fail” error. No such precautionary warning logic is available in Objective C and the code has to be manually confirmed to avoid such issues.
14 SWIFT language that is available today isn’t the finished product. Apple is still working on it, and it’s highly likely that new features will be added over the coming months. Objective C is established.
15 PLAYGROUNDS – This tool lets you see the effects of changes or additions to code as you type, without going through the time-consuming rigmarole of running the code through the compiler and executing it. No such tool in Objective C for visualization.
16 You can concatenate strings easily using “+=” and compare strings using “==” instead of the more cumbersome “isEqualToString:” Same features available here as well but not as simple as in SWIFT. Eg:-“isEqualToString:” is used for “==”.
17 A tuple lets you group multiple elements into a single compound variable. There are no tuples in Objective C.
18 The collections in Swift have mutability. There are no “mutable” counterparts to Array and Dictionary. Instead, you use the standard let and var. This allows the compiler to reason about such collections and make optimizations as appropriate. No such mutability options here.

Seeing the above mentioned features of both Objective C and SWIFT, it is difficult to see huge downsides of using SWIFT over Objective C, as a programming language. The seasoned application developers will not have to spend lot of time in learning coding.

Another great feature of SWIFT is its interoperability with existing Objective C, therefore programmers holding proficiency in Objective C can easily understand the nuances of SWIFT.

Conclusion

SWIFT as I understand is another check-point in this story of evolution of functional programming languages. It is the first of the pseudo-functional programming languages which is lining up to become industry standards. SWIFT is definitely a big leap which I think can positively replace Objective C absolutely.

There was one question which triggered this complete research- Why did they shift to SWIFT when Objective C was serving Apple well?

Perhaps Apple was desperate to not miss an opportunity.
Perhaps Apple was tired of being too cautious.
Perhaps the competition in the market made it a necessity to up the interest in their technologies.

Apple however is still thee giant in the mobile industry, they did not have to do anything yet they decided to go for it. Why?

The answer to the same now seems rather simple- It is good to have something which is productive but the search for the best should never cease. And when you sniff at something creative, you should go- rather leap for it. Innovate till you live…

Sounds almost like a life lesson…

But then, is that not all what Steve Jobs was about?

Steve Jobs Quotes

The following two tabs change content below.
Rachit Agarwal

Rachit Agarwal

Director and Co-Founder at Algoworks Technologies
Rachit is leading the mobility business development function, mobility strategy and consulting practice at Algoworks. He is an expert of all mobile technologies and has experience in managing teams involved in the development of custom iPhone/iPad/Android apps.
Rachit Agarwal

Latest posts by Rachit Agarwal (see all)

Rachit AgarwalShift to SWIFT: An Unusual Journey from Objective C
  • Aftab Alam

    5 years in making, this language is surely going to cut development cost and effort previously
    needed to produce amazing iOS Apps. Deriving it’s inspiration from some of the best programming
    languages of this time and putting features modern developers are already aware of, Apple have introduced a language that may be a delightful surprise but still looks very much required step.

    Thanks for this brilliant post. You must put this on Medium too.