Telerik blogs
I remember it all so well, I was at WWDC 2014, when Apple first announced a new programming language for iOS called Swift. The first thought that passed through the minds of most attendees was something along the lines of:
  • Wait...what?
  • I love Objective-C, now I gotta learn another language?
  • Is this the only way to build apps for iOS 8?
Apple quickly put most of the developers in the room at ease as they gently introduced Swift and provided the answers they were looking for. Apple announced that iOS developers who use Swift would benefit from a modern language that included a plethora of new features such as strong typing, type inference, generics, etc. These are all features that Objective-C developers were excited about, but what was the cost? It turns out the cost was learning the Swift programming language. While learning a new programming language certainly didn't scare away any Objective-C developers, none of the new features in Swift were show-stoppers. They have been using Objective-C to build mobile apps since March 6th, 2008 with iPhone OS. Things were quite different with developers that either had little or no experience developing with Objective-C. Their thoughts seemed to be the following:
  • Yes! I have successfully avoided Objective-C.
  • Just a .swift file no header or implementation files! Awesome!
  • Total rip-off of insert language here!
The rest of the talk all they could hear was Swift, Swift and more Swift. The key takeaway was that Swift was the replacement for Objective-C... in the future (with that last part being quickly forgotten).

A Message To the Swift Developer

01 Let's look at the following Objective-C snippet for a multi-dimensional array that displays the values in the output window in Xcode:
#import <Foundation/Foundation.h>

int main ()
{
    /* an array with 5 rows and 2 columns*/
    int a[5][2] = {{0,0}, {1,2}, {2,4}, {3,6},{4,8}};
    int i, j;

    /* output each array element's value */
    for ( i = 0; i < 5; i++ )
    {
        for ( j = 0; j < 2; j++ )
            {
                NSLog(@"a[%d][%d] = %d\n", i,j, a[i][j] );
            }
    }
    return 0;
}
The results are:
a[0][0] = 0
a[0][1] = 0
a[1][0] = 1
a[1][1] = 2
a[2][0] = 2
a[2][1] = 4
a[3][0] = 3
a[3][1] = 6
a[4][0] = 4
a[4][1] = 8
Does anything look familar to you? Maybe the declaration of 'i' and 'j', and the for loop. But what is going on with the declaration of 'a' or what is that silly syntax for NSLog? I know your don't want to write this code, neither do I. Regardless of what we want, this is what we are going to be looking at... for the time being that is.

Why Should I learn Objective-C since Swift just launched?

02 Good question, let me address a few reason why.

Debugging a "nasty" bug

Have you built and published an app in any mobile store? If so, you have certainly ran into a nasty bug somewhere in the development process. I know I did...many of them. Regardless if you are using Swift or Objective-C to write your app, the underlying framework was written in Objective-C. Bugs that are deep in the execution stack will require more than knowledge of the Swift language.

Even the "not so nasty" bug

I was writing an app in Swift and I encountered a problem with the TableView that was suppose to show data, but didn't. I did what any "great" programmer would do and did a quick search on Google for table view section ios empty. From the search results, you will quickly see that it included many solutions, but unforunately they all involved Objective-C code. What if we included Swift in the search? Unforunately, we don't have a solution but a getting started guide as of this writing. How long will it take before the solutions include Swift? One year? Two years? No one knows, but we know that the developer community speaks Objective-C.
The iOS developer community speaks Objective-C.

History taught us that the transition is going to TAKE time

How many times did cringe when you saw 'release' and 'retain' well after (Automatic Reference Counting) ARC had been implemented. Apple released a transition guide that was supposed to ease the pain. Instead many developers went with habit and keep using manual reference counting. What about AutoLayout? Most developers tried it at first through the designer and couldn't get the effect that they wanted, so did it through code and still didn't get what they wanted, then just dismissed it by saying "until the next version of Xcode comes out." These things take time for developers to adopt, and that was just two examples.

Demo Code != Production Code

We saw how fast Swift was in the WWDC keynote, but how fast is it... really? There are comparisons on various blogs and StackOverflow but they are using the various builds of Swift. How does Swift perform in a real-world application that needs the speed we are used to with Objective-C? Rest assured with time, Swift will get better. But do you have time to wait?

Swift is Still Evolving

Swift knows it's purpose, but nothing beats the experience of it's big brother, Objective-C. If you need to add C++ code to an iOS app, you will need to know Objective-C.

I Didn't Say Ignore It

I will be the first to admit that Objective-C is hard to learn and Swift is much easier. Don't get me wrong, you don't have to know everything about Objective-C to write apps for Swift, but you should be able to read it well enough to get you over the humps that I described. Swift has a very bright future, but it will take time to mature as Objective-C did. I personally look forward developing in Swift, but for now I'll stick with Objective-C. Feel free to leave your comments below. Am I right or way off base?   Pen Image provided by mcvey728 Space Shuttle Image provided by DLR/Thilo Kranz

MichaelCrump
About the Author

Michael Crump

is a Microsoft MVP, Pluralsight and MSDN author as well as an international speaker. He works at Telerik with a focus on everything mobile.  You can follow him on Twitter at @mbcrump or keep up with his various blogs by visiting his Telerik Blog or his Personal Blog.

Comments

Comments are disabled in preview mode.