Introduction to Swift

A powerful open language that lets everyone build amazing apps.

Harsh Londhekar
ADGVIT
5 min readJul 29, 2020

--

A Brief History

Swift was a surprise announcement at WWDC back in 2014, and the funny thing is that developers had no clue what was coming, but there it was — a whole new programming language. Apple used all its knowledge of Objective-C and researched a new modern style, and thus ‘Swift’ was born.

Swift programming language was founded by Chris Lattner, Doug Gregor, John McCall, Ted Kremenek, Joe Groff. The development of Swift started back in July 2010. Swift takes ideas from Objective-C, Rust, Haskell, Ruby, C#, Python, etc.

On June 2, 2014, the Apple Worldwide Developers Conference (WWDC) application became the first publicly released app written with Swift.

Glimpse from WWDC 2014(Craig Federighi introducing Swift language)

In 2015 Swift 2.0 came, and it was announced that Swift was going to go open source, which meant that the developer community as a whole could contribute to Swift language itself. Since then, every year in WWDC, Apple releases its new version of Swift, namely Swift 3, Swift 4, Swift 4.2, Swift 5.2(being the current version).

What Makes it Different?

  • Supports Playground: With the introduction of Swift language, one main feature was added in Xcode that it supports Playgrounds. It’s an interactive development environment for developers to experiment with Swift programming and allows you to see the result of your code in real-time. With the Playgrounds feature, the developer can test the piece of code separately without hampering the main project, thus saving the time also.
Swift Playgrounds
  • Type Inference: With type inference feature, it is now not mandatory to mention the data type of each variable; it explicitly identifies the data type by the initial value given to the variable. E.g.
Variable “pc” is the Int type variable as explicitly data type mentioned in the declaration.
Variable “pc” is the Int type variable as integer value has assigned to it.
  • Type-Safe Language: Type safe prevents passing different data type value to a different data type variable. It catches the exception at compile time itself if it finds any conflict in data type. Thus reduces the run time of the application.
  • Optional Data Type: This feature is used when the value to a specific variable is absent. This is similar to the nil keyword from objective-c language.
  • Unicode Support: It consists of almost all the characters in every native language. In SwiftSwift, a developer can use Unicode character for variables and constants naming convention.
  • Collection Types: Swift supports two types of collection objects, which are array and dictionary. Array contents object in an ordered manner, whereas in dictionary objects get stored in an unsorted way.

Benefits of using Swift

  • Modern: Swift is the result of different programming languages combined with experience building Apple platforms. Named parameters are easily maintained in Swift, which lets the user quickly read APIs. There is no need to type semicolons. It supports international languages and emojis. Memory is managed automatically using tight, deterministic reference counting, keeping memory usage to a minimum without the overhead of garbage collection.
  • Designed for Safety: Swift eliminates the entire classes of unsafe code. Swift uses simple three-character keywords (var and let) to make it easy to define your intent. Another safety feature that Swift has that by default Swift objects can never be nil. The swift compiler will give a compile-time error. This prevents huge runtime crashes. Swift has also provided an innovative feature of optionals. An optional may contain a nil value, but Swift forces you to deal it with ‘?’ to indicate the compiler.
  • Fast and Powerful: Swift is 3.9x faster than Python. Swift uses the LLVM compiler technology. The syntax and standard library have been optimized by Apple to make the apparent way to write your code. Swift includes low-level primitives such as types, flow control, and operators. It also provides object-oriented features such as classes, protocols, etc., allowing Cocoa and Cocoa Touch developers to work seamlessly.
  • Great First Language: Swift was designed with the intention that it can be anyone’s first language, Swift can open doors to the world of coding. Developers can use the Swift Playground App, which makes coding intuitive and fun. It consists of free courses that can help new learners build their first app.
Great programming language to explore the world of coding

Some Interesting Facts About Swift Language

  • Swift was developed for four years in secrecy; nobody knew about it outside Apple, which finally came as a surprise to the developers.
  • Swift combines the best part of Objective-C without compatibility constraints.
  • It was created by Chris Lattner, who also wrote LLVM(which can be used to develop a front end for any programming language and a back end for any instruction set architecture).
  • Swift 2 came with built-in support for checking API availability.
  • Safety is a core value idea in Swift.
  • Statements do not need to end with a semicolon as in Objective-C.
  • Enums are one of the best features introduced in Swift.
  • Apple wants your code to look beautiful and natural.

Leak Out in Non-Apple Native Platforms

  • Swift is going to be used in machine learning at Google via Tensor Flow. The credit for this again goes to Chris Lattner, who left Apple for Google and now brought Swift over to Tensor Flow.
An end-to-end open-source machine learning platform
  • We can now also write server code in Swift.
  • Swift is almost ready for windows, too; it’s been actively worked on.

Hey Guys! I am Harsh Londhekar, iOS developer at Apple Developers Group, VIT. Currently I am pursuing B.Tech in CSE at Vellore Institute of Technology, Vellore.

Thank you for reading my article!

Adios!

--

--