Swift
-

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…
-

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…
-

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 Round a Double to X Decimal Places in Swift
Round a Swift Double to any number of decimal places with a small extension, and learn when to use String(format:), NumberFormatter or…
-
![Fix: Array Extension Requires '[T]' and '[any TextContainer]' Match Fix: Array Extension Requires ‘[T]’ and ‘[any TextContainer]’ Match](https://apple-developers-inc.com/wp-content/uploads/2026/10/fix-array-extension-requires-t-and-any-textcontainer-match.jpg)
Fix: Array Extension Requires ‘[T]’ and ‘[any TextContainer]’ Match
Why a generic T: TextContainer won’t satisfy an Array extension written for [any TextContainer], and how to rewrite the extension so both…
-

Fix: Instance member ‘someVar’ cannot be used on type ‘InnerView’
SwiftUI nested structs can’t read the parent view’s properties. Use computed properties, parameter passing, @Binding or @Observable to share state cleanly.