Bird
0
0

Which method is used to save a value in UserDefaults?

easy📝 Conceptual Q2 of 15
iOS Swift - Local Data Persistence
Which method is used to save a value in UserDefaults?
AsaveValue(_:key:)
BstoreValue(_:key:)
Cset(_:forKey:)
DputValue(_:key:)
Step-by-Step Solution
Solution:
  1. Step 1: Recall UserDefaults API

    The method to save a value is set(_:forKey:) where you provide the value and key.
  2. Step 2: Eliminate incorrect method names

    Methods like saveValue, storeValue, and putValue do not exist in UserDefaults.
  3. Final Answer:

    set(_:forKey:) -> Option C
  4. Quick Check:

    Saving value method = set(_:forKey:) [OK]
Quick Trick: Use set(_:forKey:) to save values in UserDefaults [OK]
Common Mistakes:
  • Using non-existent methods like saveValue
  • Confusing UserDefaults with database APIs
  • Forgetting to specify the key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes