|
| 1 | +// |
| 2 | +// Device |
| 3 | +// Thingy |
| 4 | +// |
| 5 | +// Created by Bojan Dimovski on 19/01/2020. |
| 6 | +// Copyright © 2020 Bojan Dimovski. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import Foundation |
| 10 | + |
| 11 | +public extension Device { |
| 12 | + |
| 13 | + /// Returns the display size in inches. |
| 14 | + var displaySize: Display.Size { |
| 15 | + return display.size |
| 16 | + } |
| 17 | + |
| 18 | + /// Returns an extended info on the display, including all resolutions, scale and density. |
| 19 | + var display: Display { |
| 20 | + switch self { |
| 21 | + case .iPhone4S: |
| 22 | + return Display(size: .screen3_5Inch, resolution: CGSize(width: 320, height: 480), physicalResolution: CGSize(width: 640, height: 960), renderedResolution: CGSize(width: 640, height: 960), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB) |
| 23 | + |
| 24 | + case .iPhone5, |
| 25 | + .iPhone5c, |
| 26 | + .iPhone5s, |
| 27 | + .iPhoneSE, |
| 28 | + .iPodTouch5G, |
| 29 | + .iPodTouch6G, |
| 30 | + .iPodTouch7G: |
| 31 | + return Display(size: .screen4Inch, resolution: CGSize(width: 320, height: 568), physicalResolution: CGSize(width: 640, height: 1136), renderedResolution: CGSize(width: 640, height: 1136), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB) |
| 32 | + |
| 33 | + case .iPhone6, |
| 34 | + .iPhone6s: |
| 35 | + return Display(size: .screen4_7Inch, resolution: CGSize(width: 375, height: 667), physicalResolution: CGSize(width: 750, height: 1334), renderedResolution: CGSize(width: 750, height: 1334), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB) |
| 36 | + |
| 37 | + case .iPhone7: |
| 38 | + return Display(size: .screen4_7Inch, resolution: CGSize(width: 375, height: 667), physicalResolution: CGSize(width: 750, height: 1334), renderedResolution: CGSize(width: 750, height: 1334), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .p3) |
| 39 | + |
| 40 | + case .iPhone8: |
| 41 | + return Display(size: .screen4_7Inch, resolution: CGSize(width: 375, height: 667), physicalResolution: CGSize(width: 750, height: 1334), renderedResolution: CGSize(width: 750, height: 1334), scale: 2.0, density: 326, hasTrueTone: true, colorSpace: .p3) |
| 42 | + |
| 43 | + case .iPhone6Plus, |
| 44 | + .iPhone6sPlus: |
| 45 | + return Display(size: .screen5_5Inch, resolution: CGSize(width: 414, height: 736), physicalResolution: CGSize(width: 1080, height: 1920), renderedResolution: CGSize(width: 1242, height: 2208), scale: 3.0, density: 401, hasTrueTone: false, colorSpace: .sRGB) |
| 46 | + |
| 47 | + case .iPhone7Plus: |
| 48 | + return Display(size: .screen5_5Inch, resolution: CGSize(width: 414, height: 736), physicalResolution: CGSize(width: 1080, height: 1920), renderedResolution: CGSize(width: 1242, height: 2208), scale: 3.0, density: 401, hasTrueTone: false, colorSpace: .p3) |
| 49 | + |
| 50 | + case .iPhone8Plus: |
| 51 | + return Display(size: .screen5_5Inch, resolution: CGSize(width: 414, height: 736), physicalResolution: CGSize(width: 1080, height: 1920), renderedResolution: CGSize(width: 1242, height: 2208), scale: 3.0, density: 401, hasTrueTone: true, colorSpace: .p3) |
| 52 | + |
| 53 | + case .iPhoneX, .iPhoneXS, .iPhone11Pro: |
| 54 | + return Display(size: .screen5_8Inch, resolution: CGSize(width: 375, height: 812), physicalResolution: CGSize(width: 1125, height: 2436), renderedResolution: CGSize(width: 1125, height: 2436), scale: 3.0, density: 458, hasTrueTone: true, colorSpace: .p3) |
| 55 | + |
| 56 | + case .iPhoneXR, .iPhone11: |
| 57 | + return Display(size: .screen6_1Inch, resolution: CGSize(width: 414, height: 896), physicalResolution: CGSize(width: 828, height: 1792), renderedResolution: CGSize(width: 828, height: 1792), scale: 2.0, density: 326, hasTrueTone: true, colorSpace: .p3) |
| 58 | + |
| 59 | + case .iPhoneXSMax, .iPhone11ProMax: |
| 60 | + return Display(size: .screen6_5Inch, resolution: CGSize(width: 414, height: 896), physicalResolution: CGSize(width: 1242, height: 2688), renderedResolution: CGSize(width: 1242, height: 2688), scale: 3.0, density: 458, hasTrueTone: true, colorSpace: .p3) |
| 61 | + |
| 62 | + case .appleTV4: |
| 63 | + return Display(size: .notApplicable, resolution: CGSize(width: 1920, height: 1080), physicalResolution: CGSize(width: 1920, height: 1080), renderedResolution: CGSize(width: 1920, height: 1080), scale: 1.0, density: 0, hasTrueTone: false, colorSpace: .sRGB) |
| 64 | + |
| 65 | + case .appleTV4K: |
| 66 | + return Display(size: .notApplicable, resolution: CGSize(width: 3840, height: 2160), physicalResolution: CGSize(width: 3840, height: 2160), renderedResolution: CGSize(width: 3840, height: 2160), scale: 1.0, density: 0, hasTrueTone: false, colorSpace: .sRGB) |
| 67 | + |
| 68 | + case .iPad2: |
| 69 | + return Display(size: .screen9_7Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 1024, height: 768), renderedResolution: CGSize(width: 1024, height: 768), scale: 1.0, density: 132, hasTrueTone: false, colorSpace: .sRGB) |
| 70 | + |
| 71 | + case .iPad3, |
| 72 | + .iPad4, |
| 73 | + .iPad5, |
| 74 | + .iPad6, |
| 75 | + .iPadAir, |
| 76 | + .iPadAir2: |
| 77 | + return Display(size: .screen9_7Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 264, hasTrueTone: false, colorSpace: .sRGB) |
| 78 | + |
| 79 | + case .iPad7: |
| 80 | + return Display(size: .screen10_2Inch, resolution: CGSize(width: 1080, height: 810), physicalResolution: CGSize(width: 2160, height: 1620), renderedResolution: CGSize(width: 2160, height: 1620), scale: 2.0, density: 264, hasTrueTone: false, colorSpace: .sRGB) |
| 81 | + |
| 82 | + case .iPadPro12Inch: |
| 83 | + return Display(size: .screen12_9Inch, resolution: CGSize(width: 1366, height: 1024), physicalResolution: CGSize(width: 2732, height: 2048), renderedResolution: CGSize(width: 2732, height: 2048), scale: 2.0, density: 264, hasTrueTone: false, colorSpace: .sRGB) |
| 84 | + |
| 85 | + case .iPadPro9Inch: |
| 86 | + return Display(size: .screen9_7Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 264, hasTrueTone: true, colorSpace: .p3) |
| 87 | + |
| 88 | + case .iPadPro12Inch2G, |
| 89 | + .iPadPro12Inch3G: |
| 90 | + return Display(size: .screen12_9Inch, resolution: CGSize(width: 1366, height: 1024), physicalResolution: CGSize(width: 2732, height: 2048), renderedResolution: CGSize(width: 2732, height: 2048), scale: 2.0, density: 264, hasTrueTone: true, colorSpace: .p3) |
| 91 | + |
| 92 | + case .iPadPro10Inch, |
| 93 | + .iPadAir3: |
| 94 | + return Display(size: .screen10_5Inch, resolution: CGSize(width: 1112, height: 834), physicalResolution: CGSize(width: 2224, height: 1668), renderedResolution: CGSize(width: 2224, height: 1668), scale: 2.0, density: 264, hasTrueTone: true, colorSpace: .p3) |
| 95 | + |
| 96 | + case .iPadPro11Inch: |
| 97 | + return Display(size: .screen11Inch, resolution: CGSize(width: 1194, height: 834), physicalResolution: CGSize(width: 2388, height: 1668), renderedResolution: CGSize(width: 2388, height: 2668), scale: 2.0, density: 264, hasTrueTone: true, colorSpace: .p3) |
| 98 | + |
| 99 | + case .iPadMini: |
| 100 | + return Display(size: .screen7_9Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 1024, height: 768), renderedResolution: CGSize(width: 1024, height: 768), scale: 1.0, density: 163, hasTrueTone: false, colorSpace: .sRGB) |
| 101 | + |
| 102 | + case .iPadMini2, |
| 103 | + .iPadMini3, |
| 104 | + .iPadMini4: |
| 105 | + return Display(size: .screen7_9Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB) |
| 106 | + |
| 107 | + case .iPadMini5: |
| 108 | + return Display(size: .screen7_9Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .p3) |
| 109 | + |
| 110 | + case let .simulator(model): |
| 111 | + return model.display |
| 112 | + |
| 113 | + case .watch(.screen38mm), |
| 114 | + .watchSeries1(.screen38mm), |
| 115 | + .watchSeries2(.screen38mm), |
| 116 | + .watchSeries3(.screen38mm): |
| 117 | + return Display(size: .screen38mm, resolution: CGSize(width: 170, height: 136), physicalResolution: CGSize(width: 340, height: 272), renderedResolution: CGSize(width: 340, height: 272), scale: 2.0, density: 290, hasTrueTone: false, colorSpace: .sRGB) |
| 118 | + case .watch(.screen42mm), |
| 119 | + .watchSeries1(.screen42mm), |
| 120 | + .watchSeries2(.screen42mm), |
| 121 | + .watchSeries3(.screen42mm): |
| 122 | + return Display(size: .screen42mm, resolution: CGSize(width: 195, height: 156), physicalResolution: CGSize(width: 390, height: 312), renderedResolution: CGSize(width: 390, height: 312), scale: 2.0, density: 303, hasTrueTone: false, colorSpace: .sRGB) |
| 123 | + case .watchSeries4(.screen40mm), |
| 124 | + .watchSeries5(.screen40mm): |
| 125 | + return Display(size: .screen40mm, resolution: CGSize(width: 197, height: 162), physicalResolution: CGSize(width: 394, height: 324), renderedResolution: CGSize(width: 394, height: 324), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB) |
| 126 | + case .watchSeries4(.screen44mm), |
| 127 | + .watchSeries5(.screen44mm): |
| 128 | + return Display(size: .screen44mm, resolution: CGSize(width: 224, height: 184), physicalResolution: CGSize(width: 448, height: 368), renderedResolution: CGSize(width: 448, height: 368), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB) |
| 129 | + |
| 130 | + default: |
| 131 | + return Display(size: .notApplicable, resolution: CGSize.zero, physicalResolution: CGSize.zero, renderedResolution: CGSize.zero, scale: 0, density: 0, hasTrueTone: false, colorSpace: .sRGB) |
| 132 | + |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | +} |
0 commit comments