Introduction to Swift & Setup
What is Swift?
Swift is a powerful, intuitive programming language developed by Apple for building iOS, macOS, watchOS, tvOS, and server-side applications. It combines the performance of C/C++ with modern, safe language features.
Why Swift?
- Clean, expressive syntax
- Memory safety and optionals
- Excellent performance
- Seamless integration with SwiftUI and UIKit
Installation & Setup
Download the latest Xcode from the Mac App Store (includes Swift). For Windows/Linux, use Swift.org toolchain.
print("Hello, Swift Mastery!") print("Ready to build amazing iOS apps!")
Ready to build amazing iOS apps!
Open Xcode โ Create a new macOS Command Line Tool project. Modify it to print your name and run it.
Variables & Data Types
let vs var
Use let for constants and var for variables. Swift encourages the use of constants whenever possible.
let pi = 3.14159 var score = 0 score += 10
Operators & Control Flow
Switch Statements
Swift's switch is extremely powerful and doesn't require break.
switch grade { case "A": print("Excellent") case "B"..."C": print("Good") default: print("Keep trying") }
Optionals & Unwrapping
Dealing with Nil
Optionals are a type that can either hold a value or nil.
var name: String? = "Tim" if let actualName = name { print(actualName) }
Loops & Collections
Dictionaries
var heights = ["Taylor": 1.78, "Ed": 1.73] for (name, height) in heights { print("\(name) is \(height)m tall") }
Functions & Closures
func greet(person: String) -> String { return "Hello, \(person)!" }
Structs, Classes & Enums
Structs vs Classes
Structs are value types (copied), Classes are reference types (shared).
Protocols & Extensions
Protocol-Oriented Programming
Protocols define a blueprint of methods or properties.
Error Handling & Generics
do { try fetchData() } catch { print("Error: \(error)") }
Property Wrappers & Concurrency
Modern Swift uses async and await for concurrent code.
SwiftUI Basics
Declarative UI
struct ContentView: View { var body: some View { Text("Hello SwiftUI") } }
Capstone Project: iOS App
Create a full SwiftUI application that fetches data from an API and displays it in a beautiful list with detailed views.
// Project goals: // 1. Model your data with Codable // 2. Use URLSession for networking // 3. Build a multi-view SwiftUI navigation // 4. Implement State and Binding