Bird
0
0

Given the code below, what is the type of the array values?

hard📝 Application Q9 of 15
Swift - Collections
Given the code below, what is the type of the array values?
let values = ["1", 2, 3.0]
AArray<Any>
BArray<String>
CArray<Double>
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze mixed element types

    The array contains a String ("1"), an Int (2), and a Double (3.0).
  2. Step 2: Understand Swift type inference with mixed types

    Since elements are of different types that cannot be unified, Swift infers the array type as Array.
  3. Final Answer:

    Array -> Option A
  4. Quick Check:

    Mixed unrelated types infer to Array [OK]
Quick Trick: Mixed unrelated types infer to Array [OK]
Common Mistakes:
  • Assuming array is Array
  • Assuming array is Array
  • Expecting compilation error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes