Apple's Swift Programming Language Faster, Safer Than Objective-C

Most of the headlines from Apple's Worldwide Developers Conference 2014 last week were about iOS 8 and OS X Yosemite (v10.10), both on tap for this fall. By far the more impactful news for solution providers was about Apple's Swift programming language, a new development environment that it says will be faster and easier to use than Objective-C. The new language reportedly will work right alongside Apple's stalwart, which is used to build the majority of apps that run natively on iOS and Mac OS X.

But Objective-C is 30 years old. And after several years in development, Apple has revealed its successor to work alongside the aging veteran and transition to a more modern language that's completely under its purview. Both statically-typed languages will be part of Apple's Xcode IDE and use the same Cocoa and Cocoa Touch APIs, and the same LLVM compiler. Swift code can co-exist in a project with Objective-C code, a move that clearly was meant to help spur adoption. Registered Apple developers can download Xcode beta 6 to receive the Swift language right now.

"Swift will be a great step forward for the iOS and Mac developer communities," said Aaron Hillegass, president and founder of Big Nerd Ranch, an Atlanta-based software consultancy that specializes in iOS. "The syntax is clean and It allows the compiler to do more work for us," said Hillegass, who once worked as a developer for NeXT. With the help of a feature called type inference, developers face fewer complications when declaring types in the the new language. "If you are a good Objective-C programmer, you will have no problem making the transition to Swift because even though the syntax is different, the ideas expressed in the two languages are exactly the same." There's also a new two-phase process for initializing classes, a slight change from Objective-C that helps avoid programming mistakes (aka bugs). "Swift makes it more difficult to make dumb errors."

[Related: Apple Partners Impressed With iOS 8, OSX Yosemite Features ]

id
unit-1659132512259
type
Sponsored post

In the same vein, "Swift eliminates entire classes of unsafe code," according to Apple's Swift introductory web page. "Variables are always initialized before use, arrays and integers are checked for overflow, and memory is managed automatically." On the whole, it's as if Apple took Objective-C and tweaked the syntax to make it more foolproof; turned it into a more natural way to express the developer's intent. For example, simple three-character keywords define variables (as "var") and constants (as "let").

For that reason, Hillegass says, Swift will not be as easy to learn as some of the reports would have you believe.

"Swift is lovely, but there are many more rules enforced by the compiler," he said. "Learning Swift will be slightly more difficult than learning Objective-C, [which] is a very simple language. That said, Swift makes it more difficult to make dumb errors." Swift also will offer "Playgrounds," a window that displays the results of a program in real time before committing it to a project. If you're interested in learning Swift, Apple offers a free Swift Programming Language book. Incidentally, Apple's Script programming language is not to be confused with the Swift parallel scripting language, which was developed as an easy means to perform parallel scripting on multicore systems and clusters for scientific, engineering and other HPS apps.

PUBLISHED JUNE 9, 2014