Should I Use Objective C or Swift for Writing iOS Apps?

Simply look at these code snippets:

@import UIKit; // Other imports below
#import “ViewController1.h”
#import “ViewController2.h”
#import “MyDataModel.h”
#import “NoLongerUsed.h”

NSString *s = @”Swift is the future”;
UIViewController *vc = [[UIViewController alloc] init];
UILabel *label1 = [[UILabel alloc] init];
UIButton *button1 = [[UIButton alloc] init];
NSArray *names = @[@”John”, @”Paul”, @”George”, @”Ringo”];
NSDictionary *ages = @{@”John”: @(1940), @”Paul”: @(1942), @”George”: @(1943), @”Ringo”: @(1940)};

vs

import UIKit // No other imports needed

let s = “Swift is the future”
let vc = UIViewController()
let label1 = UILabel()
let button1 = UIButton()
let names = [“John”, “Paul”, “George”, “Ringo”]
let ages = [“John”: 1940, “Paul”: 1942, “George”: 1943, “Ringo”: 1940]

Swift is less visually noisy. Now, imagine 100,000 of code of each language. Which is more maintainable?

Less code and more maintainable code directly translates to a cost savings. The only valid argument developers have is that Swift is still an evolving language so the source will break, at least in the next version. I claim that you’re still better off writing in Swift and fixing any breaking changes than writing in Objective C. You will have done less work and your code will be safer and more maintainable.

By the way, if you want to learn Swift, there’s a lot of information available: books, blogs, and other reference material.

Advertisements

One thought on “Should I Use Objective C or Swift for Writing iOS Apps?”

  1. “Now, imagine 100,000 of code of each language. Which is more maintainable?”

    Based on my experience with medium-sized programs in both languages, I’m guessing this Objective-C program takes maybe 60 seconds to compile, and the Swift one takes at least 10 minutes.

    On my current project, I’ve done 13 builds in the past 2 hours, so on a Swift program of that size, I’d have spent an extra 2 hours or so just waiting on my compiler.

    This does not sound more maintainable to me.

    “Swift is less visually noisy.”

    That is a true statement, but the difference is not so drastic that it would translate into “2-4 times the productivity”, which is what would be required to make up for the slow compile times.

    “The only valid argument developers have is that Swift is still an evolving language so the source will break, at least in the next version.”

    I can think of lots of obvious arguments against using Swift right now. Apple can think of a few, too, apparently, because despite being the authors of the language, they’re not using it much themselves yet, even 3+ years after its first public release.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s