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

Fix: `UIDevice.model` Shows Only Device Type in Swift
Use Swift’s Darwin `uname` call to read a device identifier, map it to a friendly model name, and handle unknown devices and…
-

How to Make an Attributed String in Swift (Styled Unit Suffix)
Build an NSAttributedString in Swift, append a differently styled unit like “g” to a changing number, and show it in a UILabel…
-

Fix: Cannot Append to an NSDictionary in Swift (Use Dictionary)
NSDictionary has no append method and is immutable. Switch to a Swift Dictionary, add keys with subscript syntax, and bridge back when…
-

How to Generate a Random Number in Swift (Modern API)
Use Int.random(in:), Double.random(in:) and randomElement() in Swift, seed a generator for repeatable results, and drop arc4random without modulo bias.
-

Fix: Cannot Subscript String with an Int in Swift
Learn why Swift strings don’t support integer subscripting and get ready-to-use extensions for safe character access by index.
-

How to Change the Background Color of a SwiftUI View
Set a SwiftUI view background color that actually fills the screen, handle safe areas, and style TabView and navigation bars without white…
-

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…
