This tutorial will teach you how to use UserDefaults in SwiftUI. We are going to create a settings form view with several data entry controls such as text field, toggle, and a picker. Each of the controls will read and write its values from and to the UserDefaults database. If you’d like to learn more about …
Month: April 2020
SwiftUI Form tutorial – how to create and use Form in SwiftUI
In this tutorial we’re going to learn how to create and use forms in SwiftUI by building a simple settings form UI. Form in SwiftUI is a container which allows you to group data entry controls such as text fields, toggles, steppers, pickers and others. We’re going to explore and add each kind of data …
How to save enum in UserDefaults using Swift
UserDefaults allow you to store small pieces of data of the following types: Data, String, Number, Date, Array or Dictionary. Enumerations are not supported by UserDefaults so it’s not possible to store them directly. We are going to leverage raw values of enums to save them in UserDefaults because a raw value can be a string, a …
How to use UserDefaults in Swift
UserDefaults are meant to be used to store small pieces of data which persist across app launches. It is very common to use UserDefaults to store app settings or user preferences. UserDefaults lets you store key-value pairs, where a key is always a String and value can be one of the following data types: Data, …
Get a character from string using its index in Swift
Very often I find myself trying to access a character in string using a given index, however due to the way strings are implemented in Swift, it’s not that easy. Ideally, given a string, I’d like to access a character at index 3 like this: let input = “Swift Tutorials” let char = input[3] Unfortunately, …
SwiftUI stepper tutorial – how to create and use stepper in SwiftUI
Stepper is a user interface control which enables you to increment or decrement a value by tapping on its plus or minus elements. Stepper in SwiftUI is very similar to UIStepper in UIKit. This tutorial will teach you how to create and use a stepper in SwiftUI. In order to read a value from a …