“We had to ask ourselves the question: What would it be like if we had Objective-C without the baggage of C?” -Craig Federighi
Swift is fast and more resilient to erroneous code, not to mention it has concise syntax, making it a very powerful option for any iOS or iOS X deployment. Swift includes a number of new features and over 4000 new APIs to leverage. On top of all that, Xcode 6 has a testing area called “Play Grounds” that supports Swift– it provides a quickÂ and simple way to test classes, functions, views and algorithms while getting instant feedback.
Included in Swift’s bag of goodies, are Closures, Generics, Namespaces, Type Inference and multiple return types, among others. Swift is a strongly-typed language by default; however, it also uses type inference which again reduces code length for developers. The strong type attribute is always in place unless specified by special keyword weak.
While Swift has a number of great features, its most important characteristic is that it uses the LLVM compiler and the Objective-C runtime. This means that all new development using Swift will be compatible with Cocoa, Cocoa Touch frameworks, C, and Objective-C’s APIs and code bases. This is great news for people currently working on individual or enterprise Objective-C projects. If you are looking to transition and take full advantage of the full stack of features, Swift makes it possible.
Let’s talk about the three key features that simplify the transition to Swift:
Going along with its definition, “…able to exchange and make use of information,” this great feature creates an interface right between Swift and Objective-C. Developers can use Swift classes or pieces of code inside Objective-C and vice-versa.
The beauty here is that we can take full advantage of the patterns and practices implemented in both languages while still keeping the syntax native to Swift or Objective-C.
Mix and Match
Mix and match allow developers to combine different code files in the same project. In other words, developers can create a portion of functionality using .swift files and attach it to a project built in Objective-C code that uses .h and .m files. These files can coexist within the project. This is great for transitioning existing projects to the new language by picking and choosing what pieces of functionality to enhance or create with Swift. In addition to this, building new projects in Swift allows the flexibility to createÂ bits and pieces in Objective-C, if Objective-C is more suited to particular tasks.
This feature allows developers and architects to take an existing Objective-C project and enhance the architecture and performance by converting it to Swift. The good thing is that developers can accomplish this without having to rewrite the entire app. This is made possible by a combination of the previously-mentioned features. The optimal way to perform a migration is to switch files on a per class basis. The end result will be to switch the .m and .h files into one .swift file which will contain all the implemented functionality. Developers would not have to implement a header file, as Xcode handles this for them when working in Swift. As the integration takes place, Xcode allows you to set Swift classes that can directly interact with subclasses of an Objective-C class.
Even though developers can use features to interact between Objective-C and Swift, Objective-C cannot access some of Swift’s unique features, such as:
- Generics, Tuples
- Swift Enumerations
- Swift Structures
- Swift Top-level functions
- Swift Global variables
- Swift Type aliases
- Swift-style variadics
- Nested types
- Curried function.
Swift Adoption Rate
According to Tiobe Software, in July 2014, a month after its release, Swift entered the 16 index position as the most used programming languages. This measuring index system measures programming language use on a per month basis. It’s too early to determine if this number will increase or decrease, as Swift is still in its testing period; however, considering the qualities and features of the language and considering the use rate of Objective-C, we can expect Swift’s popularity to increase and potentially surpass its sibling.
Swift looks very promising and exciting. In my opinion, Swift is not just a programming language that is trying to fit in a saturated market of programming languages- it is a language that looks forward to facilitate the creation and continuation of successful apps. Apple took into consideration metrics that matter to individual and enterprise Software Engineers, such as time, resources and quality. As a result, Swift will be an attractive way for people to utilize iOS development as part of their development process.
At Bluefletch Mobile we stay up to date with the latest and newest technology to the point of becoming matter experts in all aspects of mobility. We are currently adopting and trying out Swift in its Beta state. Keep on the lookout for further posts on Swift and other relevant topics.
If you are interested in further reading about Swift, these books are very useful.
By Andres Avendano