0
0
iOS Swiftmobile~5 mins

Preference keys in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a UserDefaults key in iOS Swift development?
A UserDefaults key is a unique identifier used to store and retrieve user settings or preferences in UserDefaults. It helps keep data organized and accessible.
Click to reveal answer
beginner
How do you define a UserDefaults key for a Boolean value in Swift?
You create a constant string key, for example: <code>let darkModeKey = "darkModeEnabled"</code>, then use it to save or read a Boolean from UserDefaults.
Click to reveal answer
beginner
Why should you use constants for UserDefaults keys instead of hardcoding strings everywhere?
Using constants avoids typos, makes code easier to maintain, and ensures consistency when accessing stored preferences.
Click to reveal answer
beginner
How do you save a value using a UserDefaults key in UserDefaults?
Use UserDefaults.standard.set(value, forKey: key), where key is your UserDefaults key.
Click to reveal answer
beginner
How do you read a value using a UserDefaults key from UserDefaults?
Use UserDefaults.standard.bool(forKey: key) for Booleans or UserDefaults.standard.string(forKey: key) for strings, replacing key with your UserDefaults key.
Click to reveal answer
What is the main purpose of a UserDefaults key in iOS development?
ATo handle animations
BTo create UI elements
CTo manage network requests
DTo uniquely identify stored user settings
Which class is commonly used to save and retrieve preferences using keys?
AUserDefaults
BUIViewController
CNotificationCenter
DFileManager
Why is it better to use a constant for a UserDefaults key instead of a string literal?
ATo make the app run faster
BTo avoid typos and keep code consistent
CTo reduce app size
DTo improve UI design
How do you save a Boolean value to UserDefaults with a key?
AUserDefaults.standard.save(true, "key")
BUserDefaults.standard.get(true, forKey: "key")
CUserDefaults.standard.set(true, forKey: "key")
DUserDefaults.standard.store(true, "key")
Which method reads a Boolean value from UserDefaults?
AUserDefaults.standard.bool(forKey: "key")
BUserDefaults.standard.getBool("key")
CUserDefaults.standard.readBool("key")
DUserDefaults.standard.fetchBool("key")
Explain what a UserDefaults key is and how it is used in iOS Swift development.
Think about how apps remember user choices.
You got /4 concepts.
    Describe the steps to save and read a Boolean preference using a UserDefaults key in Swift.
    Focus on the methods used with UserDefaults.
    You got /4 concepts.