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

Swift Substring: Fix ‘String’ has no member ‘substringWithRange’
Fix the Swift error ‘Value of type String has no member substringWithRange’ and learn the modern prefix, suffix, index and range ways…
-

Fix: DateFormatter Returns nil When Converting a Date String in Swift
DateFormatter returns nil when the pattern doesn’t match the input string. Parse with one formatter, print with another, and handle the optional…
-

How to Read and Write a String to a Text File in Swift
Write a string to a text file and read it back in Swift using the Documents directory, plus how to load a…
-

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.
