Swift & SwiftUI
Swift and SwiftUI explained with working code examples: concurrency, data flow, layout and common compiler errors.
-

Fix: SwiftUI View Not Updating When Observable Class Property Changes
Learn why your SwiftUI view ignores changes from an @Observable class function call and how to fix the update cycle with proper…
-

How to Add a Delay in Swift Without Freezing the UI
Add a delay in Swift the right way: DispatchQueue.asyncAfter, Task.sleep in async code, and why sleep() freezes your UI. Working code for…
-

How to Run sudo pmset From a Swift App (No Deprecated APIs)
Run pmset with root rights from a Swift macOS app: read the schedule without privileges, then write it through NSAppleScript’s admin prompt.
-

Swift Array Contains: Check if an Element Exists
Swift arrays have no `include` or `has`. Use `contains(_:)` for Equatable values, `contains(where:)` for predicates, and a Set for fast repeated lookups.
-

Fix: Cannot assign to value: ‘isSheetPresented’ is a ‘let’ constant
Pass a Binding through a SwiftUI View extension without the ‘let’ constant error: forward it directly, or use wrappedValue when you rebuild…
-

How to Lock Orientation for One Screen on iPad Without Full Screen
iPad ignores per-screen orientation locks while multitasking is on. Keep a scanner screen upright by handling window resizing and preview rotation instead.
-

Fix: PDFView Selected Text Centers at Top Instead of Screen Center in SwiftUI
Learn why PDFView scrolls selected text to the top and how to center it properly using the underlying UIScrollView in SwiftUI.
-

Swift String Contains: Check for a Substring (Case-Insensitive Too)
Use String.contains for a literal substring check in Swift, and range(of:options:) when you need case- or diacritic-insensitive matching in your app.
-

How to Add an About Box to a SwiftUI iOS App
Add an About box to a SwiftUI iOS or iPadOS app: a fitted sheet with a zoom transition, one shared AboutView, and…
