Swift & SwiftUI
Swift and SwiftUI explained with working code examples: concurrency, data flow, layout and common compiler errors.
-
How to Replace dispatch_after with asyncAfter and Task.sleep
Replace the old dispatch_after call with DispatchQueue.main.asyncAfter or Task.sleep. Covers delay syntax, canceling delayed work, and SwiftUI’s .task modifier.
-

How to Check the OS Version at Runtime: iOS and macOS Swift Guide
Read the iOS or macOS version in Swift with UIDevice, ProcessInfo and #available, and learn why uname and float comparisons give you…
-

How to Add 1 Day to a Date Using Swift’s Calendar API
Add one day to a Date in Swift with Calendar.date(byAdding:), handle month and year rollover and DST correctly, plus Objective-C and reusable…
-

How to Get a Substring by Range Using String.Index
substringWithRange is gone from Swift. Learn how to slice a String with String.Index ranges, prefix/suffix, NSRange conversion, and a safe Int-offset helper.
-

Fix: Cannot Assign Value of Type ‘Int’ to Type ‘CGFloat’ in SwiftUI
Fix the Swift ‘Int’ to ‘CGFloat’ error, then make a SwiftUI view like a Pong ball move with a 60 fps timer,…
-

How to Find the Topmost UIViewController in Swift
Learn how to find the currently visible, topmost UIViewController in Swift on modern iOS, handling UIWindowScene, navigation stacks, and modals.
-

How to Organize Code with MARK Comments in Swift
Learn how to replace Objective-C #pragma mark in Swift using // MARK:, // TODO:, and extensions to organize your Xcode jump bar…
-

Fix: UIButton Image Stretches to Full Size in Swift
Stop UIButton images from stretching or filling the entire button frame in UIKit. Learn modern iOS 15+ configuration fixes and legacy inset…
-

How to Set UICollectionView Spacing Margins in Swift
Learn how to configure UICollectionView spacing margins and section insets in Swift using UICollectionViewFlowLayout, delegate methods, or Storyboards.
-

How to Get the Current Device Language in Swift
Learn how to detect the device language, get the active bundle localization, and display localized language names using Swift and Foundation.