Bird
0
0

Which Swift code snippet correctly determines if the current device is an iPad using UIDevice?

easy📝 Syntax Q3 of 15
iOS Swift - iOS Basics and Setup
Which Swift code snippet correctly determines if the current device is an iPad using UIDevice?
Aif UIDevice.current.userInterfaceIdiom == .pad { print("iPad") }
Bif UIDevice.current.deviceType == .iPad { print("iPad") }
Cif UIDevice.current.isPad { print("iPad") }
Dif UIDevice.current.interfaceIdiom == .pad { print("iPad") }
Step-by-Step Solution
Solution:
  1. Step 1: Use the correct property

    The UIDevice class provides the userInterfaceIdiom property to identify device type.
  2. Step 2: Compare with the correct enum case

    The enum case for iPad is .pad, so the comparison should be == .pad.
  3. Final Answer:

    if UIDevice.current.userInterfaceIdiom == .pad { print("iPad") } -> Option A
  4. Quick Check:

    Check property and enum case names carefully [OK]
Quick Trick: Use UIDevice.current.userInterfaceIdiom == .pad to detect iPad [OK]
Common Mistakes:
  • Using non-existent properties like deviceType or isPad
  • Using incorrect enum case names
  • Using assignment (=) instead of comparison (==)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes