Created
October 23, 2024 05:32
-
-
Save jaekong/7a80139095688eab3b0c716fc958a221 to your computer and use it in GitHub Desktop.
iPhone supported by iOS 18 and their respective Face ID sensor array - notches, or dynamic islands - dimensions (in pts)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import RegexBuilder | |
/// iPhone supported by iOS 18 and their respective Face ID sensor array dimensions (in pts) | |
/// (Notches or Dynamic Islands) | |
enum iOSDevice: Comparable { | |
case iPhoneSE(generation: Int) // 2nd, 3rd | |
case iPhoneXR | |
case iPhoneXS(size: iOSDeviceSize, globalModel: Bool) // normal, max | |
case iPhone11(moniker: iOSDeviceMoniker?, size: iOSDeviceSize) // normal, pro, promax | |
case iPhone12(moniker: iOSDeviceMoniker?, size: iOSDeviceSize) // mini, normal, pro, promax | |
case iPhone13(moniker: iOSDeviceMoniker?, size: iOSDeviceSize) // mini, normal, pro, promax | |
case iPhone14(moniker: iOSDeviceMoniker?, size: iOSDeviceSize) // normal, plus, pro, promax | |
case iPhone15(moniker: iOSDeviceMoniker?, size: iOSDeviceSize) // normal, plus, pro, promax | |
case iPhone16(moniker: iOSDeviceMoniker?, size: iOSDeviceSize) // normal, plus, pro, promax | |
case unknownNewer | |
static func < (lhs: iOSDevice, rhs: iOSDevice) -> Bool { | |
guard let lhsModel = lhs.modelNumber, let rhsModel = rhs.modelNumber else { return false } | |
guard lhsModel.0 != rhsModel.0 else { return lhsModel.1 < rhsModel.1 } | |
return lhsModel.0 < rhsModel.0 | |
} | |
var modelNumber: (Int, Int)? { | |
switch self { | |
case .iPhoneSE(2): (12, 8) | |
case .iPhoneSE(3): (14, 6) | |
case .iPhoneXR: (11, 8) | |
case .iPhoneXS(.normal, _): (11, 2) | |
case .iPhoneXS(.max, false): (11, 4) | |
case .iPhoneXS(.max, true): (11, 6) | |
case .iPhone11(nil, .normal): (12, 1) | |
case .iPhone11(.pro, .normal): (12, 3) | |
case .iPhone11(.pro, .max): (12, 5) | |
case .iPhone12(nil, .mini): (13, 1) | |
case .iPhone12(nil, .normal): (13, 2) | |
case .iPhone12(.pro, .normal): (13, 3) | |
case .iPhone12(.pro, .max): (13, 4) | |
case .iPhone13(nil, .mini): (14, 4) | |
case .iPhone13(nil, .normal): (14, 5) | |
case .iPhone13(.pro, .normal): (14, 2) | |
case .iPhone13(.pro, .max): (14, 3) | |
case .iPhone14(nil, .normal): (14, 7) | |
case .iPhone14(nil, .plus): (14, 8) | |
case .iPhone14(.pro, .normal): (15, 2) | |
case .iPhone14(.pro, .max): (15, 3) | |
case .iPhone15(nil, .normal): (15, 4) | |
case .iPhone15(nil, .plus): (15, 5) | |
case .iPhone15(.pro, .normal): (16, 1) | |
case .iPhone15(.pro, .max): (16, 2) | |
case .iPhone16(nil, .normal): (17, 3) | |
case .iPhone16(nil, .plus): (17, 4) | |
case .iPhone16(.pro, .normal): (17, 1) | |
case .iPhone16(.pro, .max): (17, 2) | |
default: | |
nil | |
} | |
} | |
var modelString: String { | |
guard let modelNumber else { return "unknown" } | |
return "iPhone\(modelNumber.0),\(modelNumber.1)" | |
} | |
var sensorHousingDimension: CGSize? { | |
switch self { | |
case .iPhoneSE(let generation): .zero | |
case .iPhoneXR: CGSize(width: 209, height: 30) | |
case .iPhoneXS: CGSize(width: 209, height: 30) | |
case .iPhone11(.none, .normal): CGSize(width: 231, height: 33) | |
case .iPhone11(.pro, _): CGSize(width: 210, height: 30) | |
case .iPhone12(.none, .mini): CGSize(width: 228, height: 35) | |
case .iPhone12: CGSize(width: 211, height: 32) | |
case .iPhone13(.none, .mini): CGSize(width: 167, height: 36) | |
case .iPhone13, .iPhone14(.none, _): CGSize(width: 162, height: 34) | |
case .iPhone14(.pro, _), .iPhone15, .iPhone16: CGSize(width: 125, height: 36) | |
case .unknownNewer: CGSize(width: 125, height: 36) | |
default: .zero | |
} | |
} | |
init?(iPhone modelString: String) { | |
let mainModelNumberRef = Reference<Int?>() | |
let subModelNumberRef = Reference<Int?>() | |
let modelRegex = Regex { | |
"iPhone" | |
TryCapture(as: mainModelNumberRef) { | |
OneOrMore { .digit } | |
} transform: { Int($0) } | |
"," | |
TryCapture(as: subModelNumberRef) { | |
OneOrMore { .digit } | |
} transform: { Int($0) } | |
} | |
guard let match = try? modelRegex.wholeMatch(in: modelString) else { return nil } | |
guard let mainModelNumber = match[mainModelNumberRef], let subModelNumber = match[subModelNumberRef] else { return nil } | |
guard let model = Self.init(iPhone: (mainModelNumber, subModelNumber)) else { return nil } | |
self = model | |
} | |
init?(iPhone modelNumber: (Int, Int)) { | |
let model: Self? = switch modelNumber { | |
case (12, 8): .iPhoneSE(generation: 2) | |
case (14, 6): .iPhoneSE(generation: 3) | |
case (11, 8): .iPhoneXR | |
case (11, 2): .iPhoneXS(size: .normal, globalModel: true) | |
case (11, 4): .iPhoneXS(size: .max, globalModel: false) | |
case (11, 6): .iPhoneXS(size: .max, globalModel: true) | |
case (12, 1): .iPhone11(moniker: .none, size: .normal) | |
case (12, 3): .iPhone11(moniker: .pro, size: .normal) | |
case (12, 5): .iPhone11(moniker: .pro, size: .max) | |
case (13, 1): .iPhone12(moniker: .none, size: .mini) | |
case (13, 2): .iPhone12(moniker: .none, size: .normal) | |
case (13, 3): .iPhone12(moniker: .pro, size: .normal) | |
case (13, 4): .iPhone12(moniker: .pro, size: .max) | |
case (14, 4): .iPhone13(moniker: .none, size: .mini) | |
case (14, 5): .iPhone13(moniker: .none, size: .normal) | |
case (14, 2): .iPhone13(moniker: .pro, size: .normal) | |
case (14, 3): .iPhone13(moniker: .pro, size: .max) | |
case (14, 7): .iPhone14(moniker: .none, size: .normal) | |
case (14, 8): .iPhone14(moniker: .none, size: .plus) | |
case (15, 2): .iPhone14(moniker: .pro, size: .normal) | |
case (15, 3): .iPhone14(moniker: .pro, size: .max) | |
case (15, 4): .iPhone15(moniker: .none, size: .normal) | |
case (15, 5): .iPhone15(moniker: .none, size: .plus) | |
case (16, 1): .iPhone15(moniker: .pro, size: .normal) | |
case (16, 2): .iPhone15(moniker: .pro, size: .max) | |
case (17, 3): .iPhone16(moniker: .none, size: .normal) | |
case (17, 4): .iPhone16(moniker: .none, size: .plus) | |
case (17, 1): .iPhone16(moniker: .pro, size: .normal) | |
case (17, 2): .iPhone16(moniker: .pro, size: .max) | |
case (17..., _): .unknownNewer | |
default: nil | |
} | |
guard let model else { return nil } | |
self = model | |
} | |
} | |
enum iOSDeviceMoniker { | |
case pro | |
} | |
enum iOSDeviceSize { | |
case normal | |
case max | |
case plus | |
case mini | |
} | |
/* | |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org/> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment