Brief Summary
This comprehensive Swift course, taught by a seasoned iOS developer, covers fundamental to advanced concepts of the Swift programming language. It is designed for individuals already familiar with the basics of programming in another language. The course begins with setting up a Swift playground and progresses through variables, operators, control flow, functions, closures, structures, enumerations, classes, protocols, extensions, generics, optionals, error handling, collections, custom operators, and modern concurrency features like async/await.
- Covers a wide range of Swift concepts, from basic syntax to advanced features.
- Provides practical examples and explanations suitable for experienced programmers.
- Highlights key differences between Swift and other programming languages.
- Emphasizes modern Swift features and best practices.
Introduction
The course introduces Swift as a programming language, focusing on its core elements such as variables, constants, structures, enums, and classes, including modern features like async and await. The instructor, Vandad, shares his extensive experience in iOS development since 2007 and Swift since its public release in 2014. The course is designed for those with basic programming knowledge in languages like Python, TypeScript, or JavaScript. It is part of a larger "Full Stack with Swift" playlist aimed at familiarizing developers with both front-end and back-end Swift development.
Modern Concepts in Swift
This chapter emphasizes that the course is not for absolute beginners and expects viewers to have basic programming knowledge. It guides viewers through setting up a Swift playground, a workspace for immediate code testing. The playground is similar to Dart and Flutter's hot reload feature, allowing automatic code execution upon changes. The chapter notes that while a Macintosh is preferable, Linux users with Visual Studio Code and Swift installed can also follow along by manually compiling code.
Variables and Constants
This section explains variables in Swift, focusing on the difference between let and var. let creates constants that cannot be reassigned, while var creates variables that can be mutated. Arrays in Swift are structures, and their mutability depends on whether they are declared with let or var. Assigning a new value to a variable does not change the original object due to Swift's value types. The chapter also warns about the use of NSmutableArray from Objective-C, which can bypass immutability even when declared with let.
Operators
The video introduces operators in Swift, including greater than, less than, plus, and multiplication. It categorizes operators into unary prefix, unary postfix, and binary infix, explaining their functions and providing examples. The section also discusses the ternary operator, cautioning against its misuse due to potential readability issues. The ternary operator is a conditional operator that assigns a value based on whether a condition is true or false.
If and Else Statements
This section covers if and else statements in Swift, explaining how to use them for conditional logic. It demonstrates comparing values and using else if for multiple conditions. The video advises against an uncommon coding style where the value being tested is placed before the variable. It also explains the use of logical AND and OR operators, cautioning against potential confusion when mixing them without parentheses.
Functions
The video explains functions in Swift, covering syntax, arguments, and return values. It demonstrates creating functions with no arguments, with arguments, and with multiple arguments. The section also discusses external and internal argument labels, as well as functions with default values. It also covers the discardableResult attribute, which allows a function to produce a value that the caller may choose to ignore.
Closures
This section introduces closures as special types of functions created inline, often passed as arguments to other functions. It explains the syntax for creating closures, including defining data types and assigning them to variables. The video demonstrates passing closures to functions and using trailing closure syntax for cleaner code. It also covers how Swift infers data types in closures and the use of shorthand argument names like $0 and $1.
Structures
The video introduces structures in Swift as value types used to group data together. It explains how to create structures, define properties, and instantiate them. Structures have implicit constructors created by the compiler, but custom initializers can also be defined. The section covers computed properties, which calculate values dynamically, and discusses the immutability of structures, explaining how to use the mutating keyword to modify them.
Enumerations
This section covers enumerations (enums) in Swift, which are used to categorize similar values. It explains how to define enums with cases and how to create instances of enums. The video demonstrates comparing enums using if statements and switch statements, emphasizing the importance of exhaustive switch statements. It also covers enums with associated values, allowing cases to carry additional data, and enums with raw values, providing a default value for each case.
Classes
The video introduces classes in Swift, highlighting their differences from structures. Classes are reference types, allowing internal mutability without the mutating keyword. The section covers the need for explicit initializers in classes, inheritance, and the use of private set to control property mutability. It also discusses designated and convenience initializers, explaining the rules for delegation between them.
Protocols
This section explains protocols in Swift, which define a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. Structures, classes, and enumerations can adopt protocols to provide concrete implementations of these requirements. The video covers protocol syntax, conformance, and how to add default implementations using extensions. It also discusses associated types in protocols, allowing protocols to be generic.
Extensions
The video explains extensions in Swift, which add new functionality to existing types. It demonstrates adding methods, computed properties, and initializers to structures, classes, and protocols. The section also covers conditional conformance, allowing extensions to apply only when certain conditions are met. Extensions are a powerful way to organize code and add functionality to existing types without modifying their original source code.
Generics
This section covers generics in Swift, which enable writing flexible, reusable functions and types that can work with any type. It explains how to define generic functions and types using type parameters. The video demonstrates using generics with protocols and associated types, allowing for more abstract and reusable code. It also discusses the use of where clauses to add constraints to generic type parameters.
Optionals
This section explains optionals in Swift, which are used to handle values that may be absent. It covers the syntax for declaring optionals, comparing them with nil, and unwrapping them using if let and guard let. The video also demonstrates optional chaining, allowing access to properties and methods of an optional value without forcing unwrapping. It also covers switching on optionals and using case let for pattern matching.
Error Handling
This section covers error handling in Swift, which allows for graceful handling of unexpected situations during program execution. It explains how to define custom error types using enums and how to throw errors using the throw keyword. The video demonstrates using do-catch blocks to handle errors, as well as the try? and try! syntax for optional error handling. It also discusses the rethrows keyword for functions that propagate errors from their closure arguments.
Collections
This section covers collections in Swift, including arrays, sets, and dictionaries. It explains how to create and manipulate arrays, including appending, inserting, and removing elements. The video demonstrates enumerating over arrays using for loops and pattern matching with where clauses. It also covers mapping, filtering, and compact mapping arrays. The section also discusses sets, which are unordered collections of unique elements, and dictionaries, which store key-value pairs.
Equality and Hashing
This section discusses equality and hashing in Swift, which are essential for working with sets and dictionaries. It explains the Equatable protocol, which allows custom types to be compared for equality, and the Hashable protocol, which allows custom types to be used as keys in dictionaries and elements in sets. The video demonstrates how to implement custom equality and hashing logic, ensuring that objects are compared and stored correctly.
Custom Operators
This section covers custom operators in Swift, which allow defining new symbols and behaviors for operators beyond the standard set. It explains how to declare prefix, postfix, and infix operators, and how to implement their corresponding functions. The video demonstrates creating custom operators for various scenarios, such as string manipulation and combining custom types.
Async Swift
This section introduces modern concurrency features in Swift, including async and await. It explains how to define asynchronous functions using the async keyword and how to suspend execution until an asynchronous operation completes using the await keyword. The video demonstrates creating tasks and using async let for concurrent execution. It also covers error handling in asynchronous code and the use of try with await.

