Affiliate Disclosure
If you buy through our links, we may get a commission. Read our ethics policy.

Apple A-Z » Apple Software

Swift

Swift

Swift is an open-source modern coding language created by Apple, designed to build apps within the Apple, Mac, and Linux system. While based off of Objective-C and other languages, it was designed to be more lightweight, more intuitive, safer, and easier-to-use compared to many of the alternatives.

● Apps tend to be faster than Objective-C and Python counterparts
● Simple to read and write
● Provides solutions to many common coding errors
● Utilizes Objective-C runtime library
● Widely considered easy to transition to from other languages
● Open source
● Free online resources available via App Store, Apple Books, Swift.org, and GitHub


Get Apple News Directly in Your Inbox


Chris Lattner, Apple's former Senior Director of Developer Tools, began developing Swift in July of 2010. Lattner and a team of developers based it off of Objective-C,  Ruby, Python, and many other coding languages. 

open-source code base Swift is open-source and used across the Apple ecosystem

In June of 2014, Apple released a beta version to registered Apple developers, and in October of 2014, Swift 1.1 was released alongside the Xcode 6.1 launch.

In late December 2015, Apple released Swift and its libraries, package manager, and debugger for public use as open-source software. Since then, it has been publicly available and anyone who wishes to contribute to the development may do so.

In 2019, Apple announced SwiftUI, a feature within Xcode that gives users a framework for declarative user-interface design across all Apple platforms.

Notable features of Swift

The most noteworthy Swift feature is its similarity to Objective-C. It uses the Objective-C runtime library, which will allow C, Objective-C, C++, and Swift code to run within a single program. 

Example of simple code Example of simple code

The language is capable of writing programs for macOS, iOS, iPadOS, watchOS, tvOS, as well as Linux. Because Swift is open-source, it's plausible that it could be incorporated into other platforms as well, including web design.

Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks – the API required to make applications work with macOS and Apple's mobile platforms such as the iPhone.

Like Objective-C, Swift supports dynamic dispatch, widespread late binding, extensible programming, and more.

Safety and bug catching

One of Apple's priorities when designing the language was to create a "safer" code. It has been equipped with features and tools to address common programming errors. 

Unlike Objective-C, it doesn't expose pointers or accessors that would lead to software vulnerabilities or possible bugs later. 

Swift initializes variables before use, checks integers and arrays for overflow, and automatically manages memory. It also enforces exclusive access to memory, guarding against many common programming mistakes. 

Optional values Swift's use of optional values enables users to avoid run-time crashes

Swift is written to be read and understood at a glance, which helps users easily locate problems if one should arise. Additionally, it limits the need for nested indentation that can lead to difficulty reading code— a common problem often referred to as the pyramid of doom. 

It also supports protocol extensibility, a system that can be applied to types, structs, and classes. This protocol-oriented programming allows for safer — and saner — implementation of abilities and features to code. 

Ease of use

While based on Objective-C, Swift was designed to be easier to use. It employs modern programming-language theory and simpler syntax, making it both easier to write and read.

It also requires less code to complete the same task as Objective-C and is often praised for being beginner-friendly.  

Speed 

As suggested by its name, Swift is designed to be lightweight and fast. It complies data much faster than Objective-C. In Objective-C, classes are treated as objects, which results in slower code. It rewrites arrays as structures, which allows the code to function much quicker than its Objective-C counterpart.

Similarly, Swift, Apple's language, is designed to be memory-efficient. Unlike Objective-C, which requires RAM for code featuring an object-link,  Swift uses structures. This design choice has reduced the amount of reference-type data and SDK classes, leading to more efficient memory usage.

According to Apple, a common search algorithm completes 2.6 times faster than Objective-C and up to 8.4 times faster than Python 2.7. 

Open Source

Since December of 2015, Swift has been open source and available to anyone who wishes to use it. It's licensed under the Apache 2.0 open source license and is generally targeted toward developers, educators, and students. Apple has said that by making an open-source language, they hope it would become one of the core programming languages of the next 20 years.

Open source You can contribute to the open-source code

“By making Swift open source the entire developer community can contribute to the programming language and help bring it to even more platforms,” said Craig Federighi, Apple’s senior vice president of Software Engineering, in a press release. “Swift’s power and ease of use will inspire a new generation to get into coding, and with today’s announcement they’ll be able to take their ideas anywhere, from mobile devices to the cloud.”

Apple encourages those interested in learning about or contributing to Swift to visit the website. It is Apple's jumping-off point for those interested in learning about Swift, as well as a community hub where users can ask questions and contribute to the active development of the language.

Those who head to the GitHub page can find the Swift compiler, debugger, standard library, foundation libraries, package manager, and REPL. 

Learning Swift

The Swift Programming Language

Alongside its beta launch in 2014, Apple released The Swift Programming Language, a 500-page manual that can be downloaded free from Apple Books. 

The Swift Programming Language serves as both a guide and a reference material that coders and programmers can reference back to as needed. 

The book starts with a twenty-page introduction that sets up the basics of the language, which is often enough for experienced programmers coming from another code like Ruby or C++. 

The rest of the book shows how one would actively develop an app, starting simple with a print "Hello World" script, and building on more complex themes as it introduces new points.

Swift Playgrounds

Swift Playgrounds is an iPad app developed by Apple that is designed to make learning to code easy for anyone. Apple suggests anyone eight or older could benefit from using the app, and the interactive environment encourages experimentation.

iPad app for training Swift Playgrounds on iPad, showing a user how to code a 'for loop'

Additionally, Apple released a Mac Catalyst version of the app. Playgrounds originated from Xcode, where users can quickly mock up ideas for programs, apps, and user interfaces without creating a complete product. This lends itself well to troubleshooting, prototyping, and experimentation, and many professionals have cited that it makes for faster development.

Those who want to code entire apps within Playgrounds and ship them to customers can do so starting in iPadOS 15 — all without touching Xcode on a Mac.

Swift Playgrounds is free, and those interested can learn more about it here.