Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update convention #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 45 additions & 46 deletions Source/iOS/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,46 @@ open class Device {
return versionCode
}

static fileprivate func getVersion(code: String) -> Version {
static fileprivate func getVersion(by code: String) -> Version {
switch code {
/*** iPhone ***/
case "iPhone3,1", "iPhone3,2", "iPhone3,3": return .iPhone4
case "iPhone4,1", "iPhone4,2", "iPhone4,3": return .iPhone4S
case "iPhone5,1", "iPhone5,2": return .iPhone5
case "iPhone5,3", "iPhone5,4": return .iPhone5C
case "iPhone6,1", "iPhone6,2": return .iPhone5S
case "iPhone7,2": return .iPhone6
case "iPhone7,1": return .iPhone6Plus
case "iPhone8,1": return .iPhone6S
case "iPhone8,2": return .iPhone6SPlus
case "iPhone8,3", "iPhone8,4": return .iPhoneSE
case "iPhone9,1", "iPhone9,3": return .iPhone7
case "iPhone9,2", "iPhone9,4": return .iPhone7Plus
case "iPhone10,1", "iPhone10,4": return .iPhone8
case "iPhone10,2", "iPhone10,5": return .iPhone8Plus
case "iPhone10,3", "iPhone10,6": return .iPhoneX
case "iPhone11,2": return .iPhoneXS
case "iPhone11,4", "iPhone11,6": return .iPhoneXS_Max
case "iPhone11,8": return .iPhoneXR
case "iPhone12,1": return .iPhone11
case "iPhone12,3": return .iPhone11Pro
case "iPhone12,5": return .iPhone11Pro_Max
case "iPhone3,1", "iPhone3,2", "iPhone3,3": return .iPhone4
case "iPhone4,1", "iPhone4,2", "iPhone4,3": return .iPhone4S
case "iPhone5,1", "iPhone5,2": return .iPhone5
case "iPhone5,3", "iPhone5,4": return .iPhone5C
case "iPhone6,1", "iPhone6,2": return .iPhone5S
case "iPhone7,2": return .iPhone6
case "iPhone7,1": return .iPhone6Plus
case "iPhone8,1": return .iPhone6S
case "iPhone8,2": return .iPhone6SPlus
case "iPhone8,3", "iPhone8,4": return .iPhoneSE
case "iPhone9,1", "iPhone9,3": return .iPhone7
case "iPhone9,2", "iPhone9,4": return .iPhone7Plus
case "iPhone10,1", "iPhone10,4": return .iPhone8
case "iPhone10,2", "iPhone10,5": return .iPhone8Plus
case "iPhone10,3", "iPhone10,6": return .iPhoneX
case "iPhone11,2": return .iPhoneXS
case "iPhone11,4", "iPhone11,6": return .iPhoneXS_Max
case "iPhone11,8": return .iPhoneXR
case "iPhone12,1": return .iPhone11
case "iPhone12,3": return .iPhone11Pro
case "iPhone12,5": return .iPhone11Pro_Max


/*** iPad ***/
case "iPad1,1", "iPad1,2": return .iPad1
case "iPad1,1", "iPad1,2": return .iPad1
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return .iPad2
case "iPad3,1", "iPad3,2", "iPad3,3": return .iPad3
case "iPad3,4", "iPad3,5", "iPad3,6": return .iPad4
case "iPad6,11", "iPad6,12": return .iPad5
case "iPad7,5", "iPad7,6": return .iPad6
case "iPad4,1", "iPad4,2", "iPad4,3": return .iPadAir
case "iPad5,3", "iPad5,4": return .iPadAir2
case "iPad11,3", "iPad11,4": return .iPadAir3
case "iPad2,5", "iPad2,6", "iPad2,7": return .iPadMini
case "iPad4,4", "iPad4,5", "iPad4,6": return .iPadMini2
case "iPad4,7", "iPad4,8", "iPad4,9": return .iPadMini3
case "iPad5,1", "iPad5,2": return .iPadMini4
case "iPad3,1", "iPad3,2", "iPad3,3": return .iPad3
case "iPad3,4", "iPad3,5", "iPad3,6": return .iPad4
case "iPad6,11", "iPad6,12": return .iPad5
case "iPad7,5", "iPad7,6": return .iPad6
case "iPad4,1", "iPad4,2", "iPad4,3": return .iPadAir
case "iPad5,3", "iPad5,4": return .iPadAir2
case "iPad11,3", "iPad11,4": return .iPadAir3
case "iPad2,5", "iPad2,6", "iPad2,7": return .iPadMini
case "iPad4,4", "iPad4,5", "iPad4,6": return .iPadMini2
case "iPad4,7", "iPad4,8", "iPad4,9": return .iPadMini3
case "iPad5,1", "iPad5,2": return .iPadMini4

/*** iPadPro ***/
case "iPad6,3", "iPad6,4": return .iPadPro9_7Inch
Expand All @@ -82,7 +82,7 @@ open class Device {
}
}

static fileprivate func getType(code: String) -> Type {
static fileprivate func getType(by code: String) -> Type {
let versionCode = getVersionCode()

if versionCode.contains("iPhone") {
Expand All @@ -98,11 +98,11 @@ open class Device {
}
}

static public func version() -> Version {
return getVersion(code: getVersionCode())
static public var version: Version {
return getVersion(by: getVersionCode())
}

static public func size() -> Size {
static public var size: Size {
let w: Double = Double(UIScreen.main.bounds.width)
let h: Double = Double(UIScreen.main.bounds.height)
let screenHeight: Double = max(w, h)
Expand Down Expand Up @@ -150,8 +150,8 @@ open class Device {
}
}

static public func type() -> Type {
return getType(code: getVersionCode())
static public var type: Type {
return getType(by: getVersionCode())
}

@available(*, deprecated, message: "use == operator instead")
Expand All @@ -169,24 +169,23 @@ open class Device {
return size.rawValue > self.size().rawValue ? true : false;
}

static public func isRetina() -> Bool {
static public var isRetina: Bool {
return UIScreen.main.scale > 1.0
}

static public func isPad() -> Bool {
static public var isPad: Bool {
return type() == .iPad
}

static public func isPhone() -> Bool {
static public var isPhone: Bool {
return type() == .iPhone
}

static public func isPod() -> Bool {
static public var isPod: Bool {
return type() == .iPod
}

static public func isSimulator() -> Bool {
static public var isSimulator: Bool {
return type() == .simulator
}

}
4 changes: 2 additions & 2 deletions Source/macOS/DeviceMacOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Device {
return String.init(validatingUTF8: model) ?? ""
}

static private func getType(code: String) -> Type {
static private func getType(by code: String) -> Type {
let versionCode = Device.getVersionCode()
if versionCode.hasPrefix("MacPro") {
return Type.macPro
Expand Down Expand Up @@ -77,7 +77,7 @@ public class Device {

static public func type() -> Type {
let versionName = Device.getVersionCode()
return Device.getType(code: versionName)
return Device.getType(by: versionName)
}

}