Swift: Pattern Matching

Disclaimers I’m on the path of learning these complex topics, so if you find a mistake, please let me know at @lintuxt The ideas, concepts, stories, and examples of this post are ALL a product of my invention. Any similarities with reality are just a pure coincidence. The post assumes some basic knowledge about if/else and switch statements in Swift. Pattern Matching in Swift Pattern Matching is one of the flagships of the Functional Programming paradigm, and Swift has you covered....

May 28, 2024 · 5 min

Swift: Set of Strings and Integers

Strings + Integers This demo shows one way of implementing a mix of types in a Set. Code Sample enum StringOrInt: Hashable, CustomStringConvertible { case string(String) case int(Int) var description: String { switch self { case .int(let int): return String(int) case .string(let string): return string } } } var mixedSet: Set<StringOrInt> = Set([.string("@lintuxt"), .int(0), .string("@lintuxt"), .int(1)]) print(mixedSet) /* Output: [0, 1, @lintuxt] */

May 28, 2024 · 1 min

iOS: Remove Storyboards

How to Remove the Dependency of Main.storyboard File in an iOS Project 1) Delete Main.storyboard File In the project navigator, delete the Main.storyboard file (when prompted, click “Move to Trash”). 2) Delete “Storyboard Name” Reference in Info.plist File In the project navigator, select the Info.plist file. Press Cmd+F and type “Storyboard Name” to find and delete the highlighted line. (To delete, use Cmd+Backspace) 3) Delete “UIKit Main Storyboard …” Reference from Build Settings In the project navigator, select the very first row (project name) and on the right side, select the “Build Settings” tab....

May 28, 2024 · 1 min

SwiftUI: Split The Check App

This is a very short sample of an app that allows calculating how much every person should pay based on the check, the tip, and the number of people. Credits: This app is based on the course “100 Days of SwiftUI” by @twostraws. Code Sample import SwiftUI struct ContentView: View { @State private var checkAmount = 0.0 @State private var peopleQuantityIndex = 0 @State private var tipPercentage = 18 @FocusState private var shouldShowKeyboard: Bool static let currencyCode = Locale....

May 28, 2024 · 1 min

SwiftUI: Cheatsheet

SwiftUI Cheatsheet A friendly way to remember some SwiftUI snippets. SwiftUI Children Limits SwiftUI by default limits its children to 10. However, this doesn’t mean that we can’t have more than ten elements in the same view. We just need to add the Group {...} directive. In the following example, it can be noticed that we have seven children under the Form {...} directive and one of them is a Group {....

May 27, 2024 · 2 min