Bird
0
0

What will this Swift code print on an iPhone device?

medium📝 Predict Output Q4 of 15
iOS Swift - iOS Basics and Setup
What will this Swift code print on an iPhone device?
let device = UIDevice.current
switch device.userInterfaceIdiom {
case .phone:
    print("iPhone detected")
case .pad:
    print("iPad detected")
default:
    print("Other device")
}
AiPad detected
BiPhone detected
COther device
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Identify device userInterfaceIdiom

    On an iPhone, userInterfaceIdiom is .phone.
  2. Step 2: Match switch case to device idiom

    The case .phone matches and prints "iPhone detected".
  3. Final Answer:

    iPhone detected -> Option B
  4. Quick Check:

    Switch on userInterfaceIdiom prints iPhone detected [OK]
Quick Trick: userInterfaceIdiom .phone means iPhone [OK]
Common Mistakes:
  • Confusing .phone with .pad
  • Ignoring default case
  • Assuming compilation error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes