The Swift Creation of iOS Applications

Henry Oyuela

6.04.2014

SwiftswiftLet me just start off by saying that I am an Android Developer more than an iOS developer. For those of you who aren’t aware, there is a bit of quarrel between the two sides when it comes to what is the best platform for development. However, I have to give credit where credit is due and this new programming language, Swift, that Apple has revealed at WWDC looks pretty awesome. Product Owners, you are probably shrugging your shoulders and saying “Meh, how does this help the product?” and some developers are probably thinking “Oh great, now I have to learn a whole new programming language?”. So just to shine a light on what this all means, in case you missed the WWDC, here are a couple of things that will hopefully help you appreciate what this all means:

Less Mistakes, More Development

The new programming language allows developers to focus on what is being developed and making it virtually impossible to make a mistake resulting in fewer defects. This in turn reduces the cost of development, because the developer will not have to spend time fixing compiler issues, analyzing a performance or memory issue. 

A couple of things mentioned that the new language supports are Inferred types and Memory managed automatically. Ok so that is cool, but what does it mean? Allow me elaborate on this a little bit.

Inferred Types will mean that the developer won’t have to concern themselves on variables types when declaring them because the framework will figure it out for them. Several modern day programming languages have this built into them already including Scala, C# and C++11. This translates into saving time because developers also won’t need to worry whether or not the memory they have allocated for a variable is of the right type, instead the framework will take care of that for them. Not to mention the code is cleaner, no casting required or additional code to make sure it compiles correctly.

Automatic Memory Management means a developer won’t have to worry about memory leaks and tracking when some piece of memory allocated for the application has to be released. Let me speak from experience that chasing a Memory Leak is a very time consuming process. It can take days sometimes to find said leak, and that is cutting into the time where a new feature can be added or feature improved.

Enhanced Code Readability

Code readability is super important for getting things done fast. Not all developers are poetry writers, but having a language that allows you to structure your code, force best practices and reduce the amount of code required for a feature helps reduce the cost because again, it helps save time. The time a new developer has to learn a piece of code can be extremely costly and with Swift you can achieve what you could before with Objective-C but with fewer lines of code.

Objective-C is quite verbose and not the easiest language to learn. Swift is helping developers create applications by reducing the amount of work to write a piece of functionality. The reduction of the verbosity also helps teams work together by allowing them to add structure to code through the use of namespaces. These namespaces will help organize and structure the code, while allowing for classes with the same name thus avoiding collisions. By allowing a developer to develop their classes without having to worry about potentially bringing in a third-party library with the same name, they can avoid wasting time fixing collisions. 

The Power of Scripting

Swift provides the power of a scripting language with the access to the native features. Some advantages to having a script language are:

  • easy to learn and use
  • minimum programming knowledge or experience required
  • allow complex tasks to be performed in relatively few steps
  • editing and running code is fast

Don’t believe me on this? Show this language to a web developer and ask them to write an iOS application. Chances are they would ramp up way quicker now then they would have with something like Objective-C. So again what does this mean? Yes you guessed right, it reduces cost, because you can leverage existing web expertise to gain knowledge on developing on iOS. Apple is essentially increasing its development community this way because now web developers will find similarities with what they have seen in the past with scripting languages they have used before.

Realtime Results

The story continues with increasing the speed of development and reducing development cost with the introduction of the playground into Xcode. The playground allows developers to see their code run as soon as they make an edit into their code. That is probably by far the coolest thing about this new Programming Language.

I flipped out when I saw this because this is HUGE!! So let me explain why.

Before developers would have to write their code, compile it (which can be lengthy), fix any compiler issues, then deploy the code into the emulator or device to see if it worked. Then if it didn’t work, they would have to go back to the code and try again. Now, a developer can code and view their results instantly as they are making the changes. Needless to say this reduces cost and increases productivity of a developer tremendously.

Increased Performance

On top of all these new benefits to Swift, the performance of Swift is impressive. They demonstrated some benchmarks at the WWDC where swift was much faster than existing Objective-C  when running process intensive algorithms such as a sort or an RC4 encryption algorithm. Not much details were given about the benchmarks, but needless to say it can be assumed that this language will be much faster because of the reduction of code for developing features and the fact that you can instantly see your code running while you are coding it.  

Interoperability

Finally, the concern that most would have is; What does this mean for my existing applications? How will this legacy code be handled? Do I have to rewrite everything? Well Apple thought of that too and has created the language such that it can co-exists with existing Objective-C code. Further more, it has provided steps to migrate the code and improve the architecture, logic and performance by replacing it with Swift.

To start using Swift you will need to download the beta release of Xcode 6. Refer to the reference library for more information on Swift.

Conclusion

These are just some of the benefits to the new iOS Swift programming language. As a developer I definitely appreciate what Apple has created here and is clearly making a dramatic change in the paradigm of how Native Applications are developed. Considering there is an ongoing debate to go Native or Hybrid when developing applications. In my opinion, Native continues today to be the way to go for building great looking applications and the concern is always the cost. However, with a new framework like Swift, that cost gets cut down because of the speed in which features can be developed. Furthermore, Apple is setting a trend on how development should be for Native Applications. So I hope Google and Microsoft are listening, because these types of frameworks are what increase and grow the development community. 

Happy Coding!

Photo Credit: Tim Stevens/CNET