At this year’s WWDC Apple surprised all attendees by unveiling its new programming language, Swift. Apple’s chief of engineering Craig Federighi, revealed that Swift is “safe, modern and powerful” and will be replacing Objective-C in the months to come. There’s no denying that this is a big step for Apple but just what does it mean for app development and what impact could it have? Let’s find out more.
What Is Swift?
Taking four years to develop, Swift is Apple’s new programming language that will replace Objective-C as the main language used to develop apps on the iOS and OSX platforms. In order to appeal to the young, up-and-coming developers, Swift combines features from other modern languages like C#, Python and Haskell but brings with it the best features of Objective-C and C. Apple has tried to make sure that the transition will be as seamless as possible for developers by making it fully binary compatible with current Objective-C libraries and ensuring it still works closely with Cocoa frameworks.
Why The Change?
Objective-C has allowed Apple to have full control over its technology stack and made it easy to add new features during the time of its use but the language is now old and relatively unsafe so Apple’s aim is to have a safer, more modern language that developers want to use. Apple also says that Swift will provide a speed advantage for developers, for example an object sort will run 3.9x faster than an implementation of the same algorithm in Python. That also makes it faster than Objective-C.
Type Safety – Swift’s complier can help to stop type-related bugs and optimize certain call sites. It uses vtable dispatch, much like C++, resulting in a code that runs faster.
Type Inference – Swift’s compiler is able to infer type based on what value a variable is being set to, therefore it will no longer be necessary to annotate variables with type information.
Control Flow – The switch statement sees a big change in Swift, as it will be able to match ranges, elements, enums and boolean expression.
Apple also points out that Swift will have the following features:
- Closures (similar to blocks in C and Objective-C) unified with function pointers
- Tuples and multiple return values
- Fast and concise iteration over a range or collection
- Structs that support methods, extensions, protocols.
- Functional programming patterns, e.g.: map and filter
A More Accessible Language
Objective-C was notorious for being a difficult language for newbies to master but so far Swift is looking more accessible. It will be interesting to see how developers take to Swift and whether non-Apple developers are persuaded to make the change and take up app development for the iOS and OSX platforms. What do you think?