DEV Community

b.chau504
b.chau504

Posted on

Exploring Swift

With more people owning mobile phones than toilets, the thought of mobile app development seemed like a good idea. So I wanted to explore it a little more.

There are two types of mobile app development that you can get into, native and cross-platform. Selecting between the two is one of the most important choices to make when getting into mobile app development.

A brief description of the two:

Cross-platform development is as it sounds; it refers to the process of developing an app that functions across many platforms. This is accomplished through the use of technologies such as React Native, Xamarin, and Flutter, and the resulting apps can be deployed on both Android and iOS.

Native App development on the other hand, involves building a mobile app entirely for a single platform. It is built using programming languages and tools that are exclusive to one platform. For instance, you can create native Android apps using Java and Kotlin and native iOS apps using Swift and Objective-C.

I wanted to delve into Swift a bit further because it is one of the most in-demand and popular languages employers and companies seek. It is also said to be one of the more beginner friendly programming languages.


Where did Swift come from?

Objective-C, Apple's previous programming language, has been mostly untouched since the early 1980s and lacked current language capabilities. Swift, which was first introduced in 2014 at Apple's Worldwide Developers Conference(WWDC), was created as a replacement. It builds on Objective-C concepts, but modernizes them to include cleaner syntax and simpler readability, maintainability, and safety to prevent crashes.

Swift outperformed Objective-C in a few areas, including type safety, security, and greater on-hardware performance. Swift is more than 8.4 times quicker than Python and more than 2.6 times faster than Objective-C.

Swift is built on modern methods found in other modern programming languages such as JavaScript. For those who are coming from Javascript like me, here are some syntax differences and similarities between Javascript and Swift.

Javascript:

console.log("Hello World");
Enter fullscreen mode Exit fullscreen mode

Swift:

print("Hello World");
Enter fullscreen mode Exit fullscreen mode

The var expression is used to declare a new variable with a value in both JavaScript and Swift.

var similar = "JS and Swift";
Enter fullscreen mode Exit fullscreen mode

Constants in Swift can also be defined as:

let favFood = "sushi";
Enter fullscreen mode Exit fullscreen mode

All variables used in JavaScript are either strings, functions, or objects because it is entirely a dynamically typed language, however in Swift, the language is completely static type based, thus you have to explicitly state the types. For instance, in Swift, you would need to write it like this to separate the definition and declaration:

var dogName: String;
dogName = "Bumi";
Enter fullscreen mode Exit fullscreen mode

Template literals
Javascript:

var firstName = "Neil", middleName = "Patrick", lastName = "Harris";
console.log(`Full name is ${firstName} ${middleName} ${lastName}`);
Enter fullscreen mode Exit fullscreen mode

Swift:

var firstName = "Neil", middleName = "Patrick", lastName = "Harris";
console.log("Full name is \(firstName) \(middleName) \(lastName)")
Enter fullscreen mode Exit fullscreen mode

Despite the fact that Swift seems to have so many fans, the language is still far from ideal. When it comes to transitioning to the new language, many developers and company owners are very cautious. This is appropriate for a number of reasons.

The language is still in its early stages. When compared to Objective C, which has been around since the 1980s, Swift was first presented to the public in 2014. Although it may seem like a long time ago, Swift is actually only 8 years old. The most recent upgrade improved ABI stability across Apple's platforms, backward compatibility with Swift versions, and documentation. Those are significant moves in the direction of making Swift a more sophisticated language.

However, concurrently, continuous updates and modifications can lead developers to question whether their project can even be built, let alone whether the code they are writing now will work with earlier versions tomorrow.

Compared to any other open source language, the Swift community is still much smaller, despite its rapid growth. Only 5.1 percent of the 83,053 respondents to the most recent StackOverflow Developer Survey reported using Swift. Therefore, if you want to use Swift for your next project, you could have difficulties finding developers that have sufficient Swift experience.


Swift is used for more than just creating apps for Apple products. It was intended to be a general-purpose language. Swift has been compatible with Linux since version 2.2 was released in 2016 for the operating system. Version 5.3 of Swift was published in 2020, making it usable on Windows. It can be used on the top three operating systems as a cross-platform programming language.

This indicates that Swift is being used to build online services and even web apps, and that developers may discover further uses for it in the future. This gives me pleasure to see the growth of this programming language and hope to work with it in the future.

Top comments (0)