Swift: How We Code Your iOS Apps Twice Faster


April 2, 2015 at 9:11 pm

4

Swift, Apple’s new programming language, is going to define the future of iOS development, regardless of developers’ opinions, be they good or bad. All the hype aside, the use of Swift can help a developer save approximately 20-50% of development time, while the number of lines of code can be reduced roughly by half. Swift is highly readable, way more than Objective-C. For developers it means convenience. For software owners it means receiving high-quality apps earlier than they could hope before.


The quality itself surely depends on skills of developers. Our iOS specialists have been putting Swift to use since it became available; they learned about lots of opportunities that speed up the development process. The product can be created faster, which means with less budget. What’s more, Swift has great prospects. It can be extremely handy for the future support of the software product, while it’s getting gradually broader use.


Here’s a typical task that appears in almost all projects; it is solved via Swift and Objective-C and compared. There is an app that uses a number of fonts. We are going to create a component that selects a font and its size for a UI element.


For visual components you have to set the font without using interface builder. Every font can be created using its name and size. For example, in our app 4 font types will be used:


1. Italic (Helvetica Neue Italic)

2. Bold (Helvetica Neue Bold)

3. BoldItalic (Helvetica Neue Bold Italic)

4. Regular (Helvetica Neue)


We also must be able to change our font family name (Helvetica Neue) at any moment – to alter the font in case of need. And naturally we mustn’t use hardcode for naming fonts. Let’s see how this task is solved with Objective-C and the new Swift.


#1. Implementation With Objective-C


First we create enum, where we list all the font types we have:




Since we can’t add functions to enum in Objective-C, we have to create a separate function for returning a font of particular type and size. For that purpose we create a class ApplicationFont with static method that does the job:




In implementation file we need to enter the name of font family and make it a constant:




In order to get the full font name, we’ll use two functions.


1. Getting the full font name: familyName + fontName:




2. Getting the font postfix (fontName) from the type:




As a result, here’s the function that returns the font:




The final implementation is as follows:


h-file:




m-file:





An example of applying a font to a UI element:




As we can see, we have a chain of switch-case, which grows as we add font types. Two h-files (interface file) and m-files (implementation file) lengthen our code.


#2. Implementation With Swift


Swift has more advanced enum than Objective-C. In Swift enum can have string values. Besides, we can add functions to enum. As a result, we can deliver the final implementation:




Applying a font to a UI element:




As we can see, with Swift we get less code. Functions are short and concise. We have no switch-case chain. And the main thing – the function that returns the font is bound to enum.


Many other tasks are handled by Swift just as fast.


That’s How We Create Apps Faster For You


Swift assists by creating the architecture. It has lots of capabilities, which have certain limitations which make it safe. The main strength budget. While the language is raw, many developers still stick to Objective-C. But everyone has to look to the future, since Swift will take the lead in IOS/OS X development anyway. Apple is quite aggressive about spreading its new language. Now every second sample for IOS 8 is written on Swift – it was when Swift was in beta officially. In a nutshell, we already need to make a shift to Swift to take care of the projects’ future.


There are various programming languages. Many people think it’s just a means of coding, and it doesn’t matter much what you use. But it does. There are languages that literally help you. They help you develop the architecture, help you avoid mistakes, help better understand third-party code. Swift is a language that’s created for developer’s convenience, a real helper. And it’s impossible to show you all advantages of this language in a short article. It can be felt only when you code with it yourself.

Frequently Asked Questions

Q1. How good are you in mobile application development ? Q2.How many years of experienced developers do you have ? Q3. How many dedicated developer can you provide at a time ? Q4. Do you need us to talk or voice chat before starting project ? Q5. What are your payment policies ?