Foundation
-

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

How to Validate an Email Address Using Swift Regex
Learn how to validate email addresses in Swift using modern Regex syntax, NSPredicate, and Foundation data detectors for iOS and macOS apps.
-

How to Create a Date from Strings and Components with Foundation
Learn how to create Swift Date objects from strings, timestamps, and calendar components safely using modern Foundation APIs without locale parsing bugs.
-

How to Format Strings Using Format Specifiers in Swift
Learn how to format strings in Swift using String(format:), C-style format specifiers, and modern FormatStyle for numbers, decimals, and dates.
-

Fix: URL Percent Encoding Does Not Escape Slashes in Swift
Learn why Swift’s percent encoding leaves slashes unescaped and how to properly encode URL query items and path parameters using Foundation APIs.
-

How to Serialize a Dictionary to JSON in Swift
Convert any Swift dictionary to JSON data or a formatted string using JSONSerialization and JSONEncoder. Handle non-string keys and invalid values.
-

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

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

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

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.