#+title: iOS Development with Swift #+date: [2024-07-20 Sat] #+filetags: :programming:swift:ios: #+identifier: 20240720T101500 * SwiftUI Essentials ** State Management - =@State= — local, value-type state - =@Binding= — two-way connection to parent state - =@Observable= — reference type, iOS 17+ - =@EnvironmentObject= — shared across view hierarchy ** Navigation #+begin_src swift NavigationStack { List(items) { item in NavigationLink(destination: DetailView(item: item)) { ItemRow(item: item) } } } #+end_src * Networking Use =async/await= with =URLSession=: #+begin_src swift func fetchData() async throws -> Data { let (data, response) = try await URLSession.shared.data(from: url) guard (response as? HTTPURLResponse)?.statusCode == 200 else { throw NetworkError.badStatus } return data } #+end_src * Keychain Store sensitive data (tokens, passwords) in the iOS Keychain, never in UserDefaults. * Testing - Unit tests with =XCTest= - UI tests with =XCUITest= - Preview testing with =#Preview=