# Swift Essentials

> The Swift language for iOS: optionals, structs vs classes, protocols, closures, enums and error handling. Free notes, key concepts, resources and a mini...

Canonical: https://www.internhack.in/roadmaps/tracks/mobile/swift
Last updated: 2026-11-28

The Swift language for iOS: optionals, structs vs classes, protocols, closures, enums and error handling.

Beginner · about 10 hours · difficulty 2/5

If you chose native iOS, Swift is your language. It favours safety and value types, and SwiftUI is built entirely on its features.

### What to learn

- **let vs var**, type inference.
- **Optionals**: `String?`, unwrapping with `if let`, `guard let` and `??`. Avoid force unwrapping with `!`.
- **Structs vs classes**: structs are copied (value semantics) and are the default in Swift; classes are shared references. SwiftUI views are structs.
- **Enums with associated values** model states like `.loading`, `.loaded([Item])`, `.failed(Error)`.
- **Protocols and extensions**: `Identifiable`, `Codable` and `Equatable` appear everywhere.
- **Closures** and trailing closure syntax.
- **Error handling** with `throws`, `try` and `do/catch`.

### Concurrency preview

Swift has `async`/`await` and actors built in. `@MainActor` marks code that must run on the main thread, which is where UI updates happen.

### Pitfalls

Retain cycles between classes and closures leak memory; use `[weak self]` where a closure outlives its owner.

**Good enough to move on:** you can decode JSON into a `Codable` struct and model a screen's state with an enum.

## Key concepts

- **let, var and type inference**
- **Optionals and unwrapping**
- **Structs vs classes**
- **Enums with associated values**
- **Protocols, extensions and Codable**
- **Closures**
- **Error handling**
- **Memory management and ARC**

## Mini project

In a Swift playground, decode a JSON array of movies into Codable structs and print the titles of those rated above 8.

## Check yourself

Why are SwiftUI views structs rather than classes, and what does value semantics buy you?

## Free resources

- [The Swift Programming Language](https://docs.swift.org/swift-book/) (Swift.org)
- [Swift.org documentation](https://www.swift.org/documentation/) (Swift.org)

Previous: [Kotlin Essentials](https://www.internhack.in/roadmaps/tracks/mobile/kotlin) · Next: [Async Code & the Main Thread](https://www.internhack.in/roadmaps/tracks/mobile/async-programming)

## More in Language Foundations

- [JavaScript Essentials](https://www.internhack.in/roadmaps/tracks/mobile/javascript-basics)
- [TypeScript for App Code](https://www.internhack.in/roadmaps/tracks/mobile/typescript)
- [Dart Essentials](https://www.internhack.in/roadmaps/tracks/mobile/dart)
- [Kotlin Essentials](https://www.internhack.in/roadmaps/tracks/mobile/kotlin)
- [Swift Essentials](https://www.internhack.in/roadmaps/tracks/mobile/swift)
- [Async Code & the Main Thread](https://www.internhack.in/roadmaps/tracks/mobile/async-programming)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Mobile App Developer Roadmap](https://www.internhack.in/roadmaps/tracks/mobile)
