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

Fix: Wrong Screen Width and Height in iOS (Use the Right Object)
Stop reading view.frame for screen size. Get the real screen, window and scene dimensions in UIKit and SwiftUI, including Split View and…
-

Fix: Using Hex Color Values in Swift UIKit
Learn two reliable ways to create UIColor from hex values in Swift — integer-based initializers and string parsing — with copy-paste extensions…
-

Remove an Element From a Swift Array (and Fix the ‘let’ Error)
Remove items from a Swift array by index or value, fix the ‘Cannot use mutating member on immutable value’ error, and pick…
-

How to Sort an Array of Custom Objects by Property in Swift
Learn why an untyped array blocks sorting and how to sort custom Swift objects by a property ascending or descending with sorted(by:)…
-

How to Dismiss the iOS Keyboard by Tapping Anywhere in Swift
Stop the iOS keyboard from covering your form. Add a tap gesture that calls endEditing, reuse it across view controllers, and handle…
-

How to Pass Data Between View Controllers in Swift (Forward and Back)
Pass data forward with properties and segues, and send selections back with delegates or closures. Clear UIKit patterns with Swift code you…
-

Swift String Replacement: Replace Characters the Right Way
Replace characters in a Swift String with replacingOccurrences, the iOS 16 replacing(_:with:) API, or a single-pass map. Includes first-match and regex examples.
-

How to Get the Length of a String in Swift (Use count)
Swift strings have no length property. Use count for visible characters, and utf16.count when you need UTF-16 offsets for NSRange or UIKit…
-

How to Make an HTTP Request in Swift with URLSession
Learn how to make GET and POST HTTP requests in Swift using URLSession, async/await, JSON decoding, status-code checks, and proper error handling.
-

How to Add an Element to a Swift Array (Append, Insert, Prepend)
Swift has no push or unshift: use append, insert(at:) and append(contentsOf:) correctly, and learn why prepending an element is never constant time.