Avatar ·

How to determine the model of the current iPhone or iOS device in Swift?

Hi everyone! I'm a beginner iOS developer and I've run into this problem: I need to programmatically determine which device the app is running on. For example, I want to show different UI elements for iPhone SE, iPhone 12 Pro Max, and iPad, or log the phone model for analytics.\n\nI tried using `UIDevice.current.model`, but it only returns generic strings like "iPhone", "iPad", or "iPod touch". I need to know the specific model: "iPhone 12", "iPhone 14 Pro Max", "iPad Pro 12.9-inch (5th generation)", and so on.\n\nI also tried using `utsname`, but the resulting code (e.g., "iPhone13,2") cannot be converted to a human-readable name without a huge dictionary. I found a bunch of solutions in Objective-C online, but I need one in Swift, preferably up-to-date.