Bird
0
0

What is the correct way to access the value for key "name" in a Swift dictionary named 'person'?

easy📝 Conceptual Q2 of 15
iOS Swift - Swift Language Essentials
What is the correct way to access the value for key "name" in a Swift dictionary named 'person'?
Aperson["name"]
Bperson.name
Cperson.get("name")
Dperson->name
Step-by-Step Solution
Solution:
  1. Step 1: Recall dictionary syntax in Swift

    Dictionary values are accessed using square brackets with the key as a string.
  2. Step 2: Match syntax to options

    person["name"] is correct; dot notation or arrow are invalid for dictionaries.
  3. Final Answer:

    person["name"] -> Option A
  4. Quick Check:

    Dictionary access uses brackets = person["key"] [OK]
Quick Trick: Use brackets with key string to access dictionary values [OK]
Common Mistakes:
  • Using dot notation for dictionary keys
  • Using arrow operator
  • Calling get() method which doesn't exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes