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 … 

 

SwiftUI slider tutorial – how to create and use slider in SwiftUI

Slider is a user interface control which enables you to select a value from a specified linear range of values by using touch. Slider in SwiftUI is very similar to a UISlider in UIKit. This tutorial will teach you how to create and use a slider in SwiftUI. In order to read a value from … 

 

How to use tuples in Swift

Tuples in Swift are very lightweight data types which enable you to create, store and pass around groups of values which can be of different types. This can be very useful when trying to return multiple values from a function in Swift as a single compound value. Creating tuples How to define a basic tuple which … 

 

How to create and use Picker with Form in SwiftUI

Picker is a control in SwiftUI which allows you to select a value from a list of possible options. In order to properly use a Picker, you need to back it with an array of possible options to choose from and a State variable storing the index of selected option in the array. In its … 

 

Algorithms in Swift: Find two elements in the array that add up to given number

By popular demand, I’m starting a semi-regular series exploring common algorithm questions asked during iOS interviews. Let me know on Twitter if you’d like to see any particular algorithm or coding question answered. In this post, let’s solve the following problem in Swift: Given an array of numbers and another number called sum, find all … 

 

How to add XCFramework to Xcode project

XCFramework is a new code distribution format introduced by Apple in Xcode 11. The new XCFramework bundle type (similar to framework bundle) now allows to support multiple architectures, platforms and simulator in one package. As XCFrameworks are gaining in popularity, iOS developers will need to know how to use them in their projects. This tutorial covers the steps … 

 

How to add missing iPhone SE simulator in Xcode 11 with iOS 13 SDKs

You might have noticed that after upgrading to Xcode 11 with iOS 13 SDKs, Xcode’s list of iOS Simulators to run your app on does not include the iPhone SE simulator any more. The iPhone SE simulator comes very handy because we still need to support this device hence the need to test on it. In this …