How to use UserDefaults in SwiftUI

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 … 

 

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