Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. and the open-source community, first released in 2014. Swift was developed as a replacement for Apple's earlier programming language Objective-C, as Objective-C had been largely unchanged since the early 1980s and lacked modern language features. Swift works with Apple's Cocoa and Cocoa Touch frameworks, and a key aspect of Swift's design was the ability to interoperate with the huge body of existing Objective-C code developed for Apple products over the previous decades. It is built with the open-source LLVM compiler framework and has been included in Xcode since version 6, released in 2014. On Apple platforms, it uses the Objective-C runtime library which allows C, Objective-C, C++, and Swift code to run within one program.
The platforms Swift supports are Apple's operating systems (Darwin, iOS, iPadOS, macOS, tvOS, watchOS), Linux, Windows, and Android. An unofficial port for FreeBSD also exists.
Swift is an alternative to the Objective-C language that employs modern programming-language theory concepts and strives to present a simpler syntax. During its introduction, it was described simply as "Objective-C without the baggage of C".
- Variables and Constants
- Declaring a variable
- Declaring a constant
- Type Annotations
- Changing Values
- Type Safety and Type Inference
- Floating Point Numbers
- Optional Binding
- Collection Types
- Properties and Methods of Arrays
- Control Flow
- For-In Loop
- While Loop
- Defining and Calling Functions
- Parameters and Return Values
- Argument Labels and Parameter Names
- Variadic Parameters
- Function Types
- Nested Functions
- Classes and Structures
- Class or Structure?
- Accessing Properties
- Memberwise initialization of Structure Types
- Value Type vs. Reference Type