devicekit / DeviceKit

DeviceKit is a value-type replacement of UIDevice.
MIT License
4.42k stars 430 forks source link

Device family based on the inch of the screen #242

Closed furiosFast closed 3 years ago

furiosFast commented 4 years ago

Hello, first of all, excellent library !! I am writing to ask you if it would be possible to add support to the device family based on the inch of the screen, for example: if Device.current.has4Inch {} thanks

karthisiva commented 3 years ago

@furiosFast Did you find a solution to this?

furiosFast commented 3 years ago

@karthisiva hi, not for now

karthisiva commented 3 years ago

@furiosFast Okay

Zandor300 commented 3 years ago

@furiosFast You could check against Device.current.diagonal

if Int(Device.current.diagonal) == 4 {
    // Your code
}

The conversion to Int is because of floating point precision. If you would check for Device.iPhone12Pro.diagional (which is 6.1), you would have to convert it to a string and check against that value because it's not a round number.

if String(format: "%.1f", Device.current.diagonal) == "6.1" {
    // Your code
}

https://github.com/devicekit/DeviceKit/blob/4cf9f057db69104851634269f7839f8d0bd346a3/Source/Device.generated.swift#L484


Actually implementing functions with Device.current.has4InchScreen would clutter up the API very much because of the great number of different screen sizes there are.