A few days ago we submitted our first app coded entirely in Swift, the new apple language, to the App Store. But, what was different? First of all, we felt much freer about how we named our objects and variables.
The advantages of programming in Swift
Unlike the unfriendly prefixes used in Objective-C, Swift now allows name spacing which makes us far less restricted in our naming conventions. This ultimately leads to a more readable and understandable code.
Swift excellently tackles one common problem; the easy algorithm development allows us to avoid writing numerous lines of code for simple tasks. This is clearly represented in the example I provide, where I move an object to transform it into a JSON format for posting it in a web service.
This is the way we did it in Objective-C:
Now, let's see how we do the same thing with Swift:
With Swift, we are doing the same task in a single line of code and the compiler identifies what we are attempting to do. We don't even have to verify if the array we are receiving is “nil”.
Swift significantly changed the way we manage the device memory, writing functions coding in blocks is easier, and this language also performs thread management. The compiler now helps us when losing a reference in a thread or when the thread is not freeing the memory the way it has to be.
So yes, in my opinion, Apple did an amazing job with Swift. We don't have to forget that we are working with a new language. Developers have been working with it for no more than a year, and although it is changing, it remains reasonably stable. We’re very close to the next Apple Worldwide Developers Conference (WWDC) and I’m sure we’ll learn what people are doing with Swift, along with a great wave of news.
Don't forget who owns Swift! In my experience, we better adapt quickly to Apple and learn Swift pretty soon. I’m not saying we should forget about Objective-C based written apps but it’s very likely that within the next year we will be faced with far more apps using Swift.
I have been programming for iOS during four years and this is the biggest change I’ve witnessed. The platform has considerably changed and I see a more open and larger Apple community.
What comes next?
This is the precise moment to evolve with Apple to take our apps and modernize them with Swift. We know the code we’ve written previously and we know exactly what it has to do and now we have a way to rewrite it smartly.
Now is the time to learn more about iOS development if you’re not 100% familiar with it. It is not that different now from programming and performing the syntax with C# or Java and I know it will be easy for you.