Bird
0
0

You want to create a typealias JSONDictionary for a dictionary with String keys and Any values. Which code correctly defines this?

hard📝 Application Q8 of 15
Swift - Data Types
You want to create a typealias JSONDictionary for a dictionary with String keys and Any values. Which code correctly defines this?
Atypealias JSONDictionary = Dictionary<String>
Btypealias JSONDictionary = [String: Any]
Ctypealias JSONDictionary = [Any: String]
Dtypealias JSONDictionary = (String, Any)
Step-by-Step Solution
Solution:
  1. Step 1: Recall dictionary type syntax

    Swift dictionaries are defined as [KeyType: ValueType].
  2. Step 2: Match required key and value types

    Keys are String, values are Any, so [String: Any] is correct.
  3. Final Answer:

    typealias JSONDictionary = [String: Any] -> Option B
  4. Quick Check:

    Dictionary alias syntax = typealias Name = [Key: Value] [OK]
Quick Trick: Use [Key: Value] syntax for dictionary typealias [OK]
Common Mistakes:
  • Using incomplete dictionary syntax
  • Swapping key and value types
  • Using tuple instead of dictionary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes