[Compare] Kotlin vs Swift – Android and iOS work towards creating a universal language.

Tram Ho

Today we will learn and compare about the 2 latest languages ​​created by Apple vs Google, for what purpose? And you can see how their incredible similarity is. And who is the first to copy and copy each other or what is the purpose ?.

When Kotlin received support from Google. People who are not familiar with Kotlin are quite interested in its compatibility / interoperability with Java, the average time required to understand it, as well as the benefits of using Kotlin in general.

In an effort to explain and introduce the language in the shortest and clearest way possible, many Kotlin developers mentioned the three-year parallel between Kotlin and iOS's second official language – Swift. Kotlin, Swift of Android has made things easier and helped create a new image for the language. However, this image also caused controversy in the iOS community, as some iOS developers did not find any detailed comparisons and found Kotlin to be a duplicate.

at the very least, it should be noted that although Swift appeared in 2013, Kotlin originated in 2011. Therefore, although the comparison of Kotlin with Swift (in this exact order) can be seen that Swift is Later introduction to many subjects and Kotlin copying was not proved.
However, is the comparison true? If yes, what is the similarity? And does its existence suggest the fact that providing apps for both iOS and Android could become easier and faster in the future? We will understand more clearly through the following article.

Syntax (Syntax)

The syntax of Swift doesn is similar to that of Kotlin: in small pieces of code there can be a similarity of characters up to 77%. The main differences can be clearly seen in the table below:

Kotlin Swift
fun func
val let
null nil
trait protocol
constructor init
: ->
Any AnyObject
!! !

The basic concept, classes and functions all have very similar expressions. Unlike Objective-C, Swift's calls are similar to those of Java and Kotlin, with their namespace system and punctuation notation. For example, how to call the function in two languages:

Kotlin Swift
fun findStore (address: String, name: String): String { func findStore (_ address: String, _ name: String) -> String {
return "Store is $ name, And The address is $ address." return "Store is (name), And The address is (address)."
} }
forecast ("Vietnam", "Cafedev.vn") forecast ("Vietnam", "Cafedev.vn")

And this is how the classes are declared in both:

Kotlin Swift
class Developer { class Developer {
var id = 0 var id = 0
fun Description () = func Description () -> String {
"A cafedev.vn with $ id." return "A cafedev.vn with (id)."
} }

Many other examples can be found in this article , and if they tell us something, it's that both languages ​​have the same original purpose of maintaining the most transparency and transparency possible. , make life easier for developers. Syntax systems of Kotlin and Swift Swift are quite effective in that regard, as they are highly appreciated by the development teams for their elegance.


Although both Swift and Kotlin are strong and static in terms of typing, they also allow working with dynamic types. In this way, languages ​​remain concise and flexible, and allow for early elimination of errors and nonconformities. Therefore, they are considered to be very safe and especially reliable for large projects.

Also, do the two languages ​​combine approaches for handling optional and safe values ​​null / nil with the Safe Navigation Operator? or Optional types. The precautions shown are almost the same in both Kotlin and Swift:

Kotlin Swift
val example: String? = null var example: String? = nil

Features, characteristics

Besides safe (functional), null (nil) and class, Kotlin and Swift have many similar features, including constants, variables, generics, protocols (traits), enumerated types, any (anyobject), error handling, and calculations. other. Some features implemented in two languages ​​share the same approach, but are called differently.

For example, in Kotlin, one can find Java lambda expressions (convenient, highly efficient, but not available for Java Android development). In Swift these are blocks or closures , terms from Objective-C. The way both expressions are called in the code is similar to the way they work.

Kotlin Swift
{ {_in
println ("Lambda Expression") print ("Closure Expression")
} }

The feature called computed properties in Swift, which is a specific attribute declaration with a 'get' call, is also available in Kotlin:

Kotlin Swift
Animal class ( Animal class {
var Genus: String, var Genus: String
var Species: String) { var Species: String
val binomialName: String var binomialName: String {
get () = "$ Genus $ Species" get {
} return " (Genus) (Species)"

Parameter names (or argument names) are also used in both languages:

Kotlin Swift
fun daysoff (vacation: Int, weekends: Int): Int = vacation + weekends func daysoff (vacation: Int, weekends: Int) -> Int {
return vacation + weekends
daysoff (5, weekends = 8) daysoff (vacation: 5, weekends: 8)

In fact, instead of listing features that exist in both languages, it's easier to list those features. Specifically, only Kotlin supports:

  • class import
  • primary constructors and data classes
  • @annotations

Also, unlike Kotlin, Swift has:

  • tuples
  • typealias
  • guard statement

The meaning behind the similarities

The two languages ​​clearly share ideology, because they solve the same problem created by their ancestral languages: they are less verbose and functional, easier to read and more convenient to work with. . At the same time, both Kotlin and Swift can interact with Java and Objective-C, respectively, allowing their use in new projects as well as maintenance of old projects.

Moreover, the strong similarities of the two languages ​​can support native development of an application for both iOS and Android. This means that applications on both platforms can share a single code, of course, because the operating system languages ​​and libraries are not the same. However, the logical approaches and application functions can be very similar, thanks to the syntax and function similarities between Swift and Kotlin. This can make development, testing and maintenance faster and easier.

Universal language for iOS and Android?

Although Swift and Kotlin are the same, what they most resemble is their predecessors. In other words, Swift and Kotlin are closing the gap between Objective-C and Java. However, a change from Java to Kotlin is still more natural and smooth than switching from Java to Swift.

In general, the idea of ​​adapting to something new is not appealing to everyone, some developers take their time to come up with a new language, just like with Swift. To make sure the transition will be less challenging means ensuring the language will eventually catch up and for a new language, this is the first and most important.

As mobile development is constantly evolving, so is technology. That's why after 5-10 years, both Kotlin and Swift can become something completely different. There is no information on whether languages ​​will continue to bridge the gap between them. However, since both iOS and Android are looking for the most convenient, safe, and fastest mobile development tool, they can eventually speak the same language someday . Hope so for everyone to be healthy when dev 2 platforms.

Share the news now

Source : CafeDev