Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In Swift, you can determine the screen size of an iPhone 4 or iPhone 5 by checking the bounds of the UIScreen object. Here's an example code snippet that shows how to do this:

let screenSize = UIScreen.main.bounds.size
if screenSize.height == 480 {
   print("iPhone 4 screen size")
} else if screenSize.height == 568 {
   print("iPhone 5 screen size")
} else {
   print("Not an iPhone 4 or 5")
}

This code first gets the size of the main screen using the bounds property of the UIScreen object. It then checks the height of the screen size, and if it matches the height of either iPhone 4 or 5, it prints the appropriate message.