PDF version of this report
You must have Adobe Acrobat reader to view, save, or print PDF files. The reader
is available for free
download.
Swift Programming Language
Copyright 2022, Faulkner Information Services. All Rights Reserved.
Docid: 00021080
Publication Date: 2202
Report Type: TUTORIAL
Preview
The Swift programming language was introduced by Apple to remove many of
the complexities associated with Objective-C while remaining, as much as possible, compatible. Introduced at the Apple Worldwide
Developers Conference in 2014 as a proprietary product, it was released to open
source for Apple and Linux platforms in December 2015. At its introduction,
Apple described it as "Objective-C without the C," meaning it does not have the complicated syntax associated with the C programming
language.
Report Contents:
Executive Summary
[return to top of this report]
The Swift programming language is designed for macOS,
iOS, watchOS, and tvOS.
Apple describes it as "the result of the latest research on programming
languages, combined with decades of experience building Apple platforms"
and says it removes unsafe constructs that exist in other languages while still
allowing Swift code to co-exist with Objective-C code in the same project. It was
designed to eventually replace Objective-C and is included in Apple’s Xcode
development environment.
Related Faulkner Reports |
Agile Software Development Tutorial |
Web Design Programs and Tools Tutorial |
Objective-C Programming Tutorial |
Description
[return to top of this report]
Swift was introduced to the Apple developer community at the company’s
Worldwide Developers Conference in 2014 as a simpler, easier to use and less
error-prone tool that would ultimately replace Objective-C. It is designed to
work with the Cocoa and Cocoa Touch object oriented API frameworks program macOS, iPhone, iPad, iPod Touch, Apple TV, and Apple
Watch. It coexists with legacy Objective-C code, allowing developers to build on
existing work without having to recode, and has been included in Xcode since
version 6.
Originally a proprietary product, Apple released Swift to
open source in December 2015. It is currently at version 5, which is included in Xcode
13.
Swift was designed for safety, eliminating hazard-prone
constructs such as pointers. Apple also claims significant performance gains
over Objective-C code, in part because programs are shorter due to streamlined syntax.
Where Objective-C requires semicolons after each statement, uses alloc and init, and declared types, Swift
eliminates the extra punctuation unless there are multiple statements on one
line, uses closures and namespaces, and supports
multiple return types and type inference. Its string handling is also improved.
In other words, modern programming disciplines developed in the thirty-plus years since
Objective-C’s creation in 1983 were built into Swift from the beginning. Yet
despite these differences, Swift and Objective-C use the same runtime, allowing
code in both languages to exist within a project. It unifies the procedural and object-oriented programming components.
Swift defines away large classes of common programming errors by
adopting these modern programming patterns,
enumerated in its documentation:
- Variables are always initialized before use.
- Array indices are checked for out-of-bounds errors.
- Integers are checked for overflow.
-
Optionals ensure that
nil
values are handled explicitly. - Memory is managed automatically.
-
Error handling allows controlled recovery from unexpected
failures.
It supports the same variable types as Objective-C, including:
- Int – integers
- Float – floating point numbers
- Double – double precision (64 bit) floating point
- Char – single character
- [ ] array – int values
- BOOL – Yes/No (or True/False)
It also includes some new types, notably the Tuple, which is a comma-separated list of types, enclosed in parentheses, such as:
var TupleName = (Value1, value2,… any number of values)
Unlike Objective-C, Swift does not need separate library imports to support functions like string handling or input/output. They are now built into the language.
The Playground feature in Swift allows programmers to execute their code immediately, without compiling, as though it were an interpreter. Playgrounds are initiated from
the Xcode UI, allowing the programmer to see what is happening in each line of code without having to build and compile an app.
Current View
[return to top of this report]
Swift’s progress has been relatively rapid. Version 1.0 was released in September of 2014, just three months after the beta was released at
the Worldwide Developers Conference. Swift 2.0 made its debut at the 2015 conference, and was released that September. In December of that year, Swift 2.2 was made open
source under the Apache License 2.0 for Apple and Linux platforms. Almost exactly a year later,
in September 2016, Swift 3 arrived. Swift 4.0 was released in September 2017 as part of Xcode 9, as well as on Github. The lastest version, Swift 5.0, came
out in March 2019, and the most recent update, Swift 5.5.2, was released in December 2021.
New Features in Swift 5
Apple cites the following primary enhancements to Swift 5.1
Standard Library – The standard library in Swift 5 includes the following features:
- String reimplemented with UTF-8 encoding, which can often result in faster code
- Improved support for raw text in string literals
- Result and SIMD vector types added to the standard library
- Enhancements to String interpolation, adding more flexibility to construct text from data
- Performance improvements to Dictionary and Set
Additional Language and Compiler Updates – Swift 5 defaults to enforcing exclusive access to
memory for both debug and release builds. It also supports dynamically callable types to help improve
interoperability with dynamic languages such as Python, JavaScript and Ruby.
Package Manager Updates – Includes a number of new features, including dependency mirroring,
target-specific build settings, customized deployment targets, and the ability to generate code coverage
data. Additionally, the swift run command now includes the ability to import libraries in a REPL without
needing to build an executable.
Migrating to Swift 5 – Swift 5 is source compatible with Swift 4, Swift 4.1 and Swift 4.2.
Outlook
[return to top of this report]
Swift is quickly becoming the language of choice for programmers of Apple devices. Its cleaner syntax and safer programming patterns
make it less error-prone. For example, since arrays are automatically checked for index overflows, program crashes or unexpected behavior from
this common error are eliminated. The current version of Xcode supports Swift 4and Swift
5, teh SwiftUI framework, and the Swift Package Manager, allowing developers already experienced with the language to
migrate to the new version at their own speed, and letting them continue to maintain existing code without painful migrations.
Apple’s direction is clear. In its Swift documentation it states, “Swift is a successor to both the C and Objective-C languages.
It includes low-level primitives such as types, flow control, and operators.
It also provides object-oriented features such as classes, protocols, and generics,
giving Cocoa and Cocoa Touch developers the performance and power they demand.” While it acknowledges the massive amount of outstanding Objective-C code,
the message is unmistakable: Swift is the way of the future.
Recommendations
[return to top of this report]
There’s no question that programmers who want to develop for Apple platforms should learn and use Swift. Although Objective-C will remain on the scene
for some time,
simply because of the number of applications using it, Swift is the platform for anything new. Ultimately, Objective-C will fade away.
However, for the time being, a working knowledge of Objective-C may be a necessity to maintain older programs. Even with binary interoperability,
some modules will be low on the list for rewrites so will have to co-exist with new Swift code.
Finally, to ensure the future of Swift, programmers should make an effort to contribute to the project, by answering questions on the forums,
reporting or triaging bugs, or by submitting fixes or new code.
The Swift Community site offers guidelines for all levels of users on how they can participate.
Web Links
[return to top of this report]
- Apple Developer-Swift:
https://developer.apple.com/swift/ - Swift Community: https://swift.org/
- Swift Download: https://github.com/apple/swift
- Swift EU Language Site: https://swiftlang.eu
- Swift Manual:
http://www.carlosicaza.com/swiftbooks/SwiftLanguage.pdf - Swift Tutorial:
https://www.tutorialspoint.com/swift/index.htm - Swift Video Tutorial:https://www.youtube.com/watch?v=6Zf79Ns8_oY
- Swift on Wikipedia:
https://en.wikipedia.org/wiki/Swift_(programming_language)
References
1 Kremenek, Ted. “Swift 5 Released!” Swift.org. March 25, 2019.
[return to top of this report]