diff --git a/Device.xcodeproj/project.pbxproj b/Device.xcodeproj/project.pbxproj index 314529b..b50848a 100644 --- a/Device.xcodeproj/project.pbxproj +++ b/Device.xcodeproj/project.pbxproj @@ -514,7 +514,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; @@ -536,7 +536,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; @@ -666,7 +666,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -687,7 +687,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).Example"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 8f9045d..3c1ec86 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -29,6 +29,12 @@ class ViewController: UIViewController { case .iPhoneSE: print("It's an iPhone SE") case .iPhone7: print("It's an iPhone 7") case .iPhone7Plus: print("It's an iPhone 7 Plus") + case .iPhone8: print("It's an iPhone 8") + case .iPhone8Plus: print("It's an iPhone 8 Plus") + case .iPhoneX: print("It's an iPhone X") + case .iPhoneXS: print("It's an iPhone Xs") + case .iPhoneXS_Max: print("It's an iPhone Xs Max") + case .iPhoneXR: print("It's an iPhone Xr") /*** iPad ***/ case .iPad1: print("It's an iPad 1") @@ -36,6 +42,7 @@ class ViewController: UIViewController { case .iPad3: print("It's an iPad 3") case .iPad4: print("It's an iPad 4") case .iPad5: print("It's an iPad 5") + case .iPad6: print("It's an iPad 6") case .iPadAir: print("It's an iPad Air") case .iPadAir2: print("It's an iPad Air 2") case .iPadMini: print("It's an iPad Mini") @@ -68,6 +75,8 @@ class ViewController: UIViewController { case .screen4_7Inch: print("It's a 4.7 inch screen") case .screen5_5Inch: print("It's a 5.5 inch screen") case .screen5_8Inch: print("It's a 5.8 inch screen") + case .screen6_1Inch: print("It's a 6.1 inch screen") + case .screen6_5Inch: print("It's a 6.8 inch screen") case .screen7_9Inch: print("It's a 7.9 inch screen") case .screen9_7Inch: print("It's a 9.7 inch screen") case .screen10_5Inch: print("It's a 10.5 inch screen") diff --git a/README.md b/README.md index 7453e5f..f49ccc1 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,15 @@ func myFunc() { case .iPhone6S: print("It's an iPhone 6S") case .iPhone6Plus: print("It's an iPhone 6 Plus") case .iPhone6SPlus: print("It's an iPhone 6 S Plus") + case .iPhoneSE: print("It's an iPhone SE") + case .iPhone7: print("It's an iPhone 7") + case .iPhone7Plus: print("It's an iPhone 7 Plus") + case .iPhone8: print("It's an iPhone 8") + case .iPhone8Plus: print("It's an iPhone 8 Plus") + case .iPhoneX: print("It's an iPhone X") + case .iPhoneXS: print("It's an iPhone Xs") + case .iPhoneXS_Max: print("It's an iPhone Xs Max") + case .iPhoneXR: print("It's an iPhone Xr") /*** iPad ***/ case .iPad1: print("It's an iPad 1") @@ -62,6 +71,7 @@ func myFunc() { case .iPad3: print("It's an iPad 3") case .iPad4: print("It's an iPad 4") case .iPad5: print("It's an iPad 5") + case .iPad6: print("It's an iPad 6") case .iPadAir: print("It's an iPad Air") case .iPadAir2: print("It's an iPad Air 2") case .iPadMini: print("It's an iPad Mini") @@ -69,6 +79,7 @@ func myFunc() { case .iPadMini3: print("It's an iPad Mini 3") case .iPadMini4: print("It's an iPad Mini 4") case .iPadPro9_7Inch: print("It's an iPad Pro 9.7 Inch") + case .iPadPro10_5Inch: print("It's an iPad Pro 10.5 Inch") case .iPadPro12_9Inch: print("It's an iPad Pro 12.9 Inch") /*** iPod ***/ @@ -98,8 +109,11 @@ func myFunc() { case .screen4_7Inch: print("It's a 4.7 inch screen") case .screen5_5Inch: print("It's a 5.5 inch screen") case .screen5_8Inch: print("It's a 5.8 inch screen") + case .screen6_1Inch: print("It's a 6.1 inch screen") + case .screen6_5Inch: print("It's a 6.8 inch screen") case .screen7_9Inch: print("It's a 7.9 inch screen") case .screen9_7Inch: print("It's a 9.7 inch screen") + case .screen10_5Inch: print("It's a 10.5 inch screen") case .screen12_9Inch: print("It's a 12.9 inch screen") default: print("Unknown size") } diff --git a/Source/Size.swift b/Source/Size.swift index fe64117..c9e53f3 100644 --- a/Source/Size.swift +++ b/Source/Size.swift @@ -9,14 +9,27 @@ public enum Size: Int, Comparable { case unknownSize = 0 #if os(iOS) + /// iPhone 4, 4s, iPod Touch 4th gen. case screen3_5Inch + /// iPhone 5, 5s, 5c, SE, iPod Touch 5-6th gen. case screen4Inch + /// iPhone 6, 6s, 7, 8 case screen4_7Inch + /// iPhone 6+, 6s+, 7+, 8+ case screen5_5Inch + /// iPhone X, Xs case screen5_8Inch + /// iPhone Xr + case screen6_1Inch + /// iPhone Xs Max + case screen6_5Inch + /// iPad Mini case screen7_9Inch + /// iPad case screen9_7Inch + /// iPad Pro (10.5-inch) case screen10_5Inch + /// iPad Pro (12.9-inch) case screen12_9Inch #elseif os(OSX) case screen11Inch diff --git a/Source/Version.swift b/Source/Version.swift index bc57180..4ea2bcf 100644 --- a/Source/Version.swift +++ b/Source/Version.swift @@ -23,6 +23,9 @@ public enum Version: String { case iPhone8 case iPhone8Plus case iPhoneX + case iPhoneXS + case iphoneXS_Max + case iphoneXR /*** iPad ***/ case iPad1 @@ -30,6 +33,7 @@ public enum Version: String { case iPad3 case iPad4 case iPad5 + case iPad6 case iPadAir case iPadAir2 case iPadMini diff --git a/Source/iOS/Device.swift b/Source/iOS/Device.swift index e137813..bc9c0ed 100644 --- a/Source/iOS/Device.swift +++ b/Source/iOS/Device.swift @@ -30,20 +30,24 @@ open class Device { case "iPhone7,1": return .iPhone6Plus case "iPhone8,1": return .iPhone6S case "iPhone8,2": return .iPhone6SPlus - case "iPhone8,4": return .iPhoneSE + 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 + /*** iPad ***/ - case "iPad1,1": return Version.iPad1 + case "iPad1,1", "iPad1,2": return Version.iPad1 case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return Version.iPad2 case "iPad3,1", "iPad3,2", "iPad3,3": return Version.iPad3 case "iPad3,4", "iPad3,5", "iPad3,6": return Version.iPad4 case "iPad6,11", "iPad6,12": return Version.iPad5 + case "iPad7,5", "iPad 7,6": return Version.iPad6 case "iPad4,1", "iPad4,2", "iPad4,3": return Version.iPadAir case "iPad5,3", "iPad5,4": return Version.iPadAir2 case "iPad2,5", "iPad2,6", "iPad2,7": return Version.iPadMini @@ -84,12 +88,12 @@ open class Device { return .unknown } } - - static open func version() -> Version { + + static public func version() -> Version { return getVersion(code: getVersionCode()) } - static open func size() -> Size { + static public func size() -> Size { let w: Double = Double(UIScreen.main.bounds.width) let h: Double = Double(UIScreen.main.bounds.height) let screenHeight: Double = max(w, h) @@ -105,14 +109,16 @@ open class Device { return .screen5_5Inch case 812: return .screen5_8Inch + case 896: + return UIScreen.main.scale == 3.0 ? .screen6_5Inch : .screen6_1Inch case 1024: switch version() { - case .iPadMini,.iPadMini2,.iPadMini3,.iPadMini4: - return .screen7_9Inch - case .iPadPro10_5Inch: - return .screen10_5Inch - default: - return .screen9_7Inch + case .iPadMini,.iPadMini2,.iPadMini3,.iPadMini4: + return .screen7_9Inch + case .iPadPro10_5Inch: + return .screen10_5Inch + default: + return .screen9_7Inch } case 1112: return .screen10_5Inch @@ -123,42 +129,42 @@ open class Device { } } - static open func type() -> Type { + static public func type() -> Type { return getType(code: getVersionCode()) } @available(*, deprecated, message: "use == operator instead") - static open func isEqualToScreenSize(_ size: Size) -> Bool { + static public func isEqualToScreenSize(_ size: Size) -> Bool { return size == self.size() ? true : false; } @available(*, deprecated, message: "use > operator instead") - static open func isLargerThanScreenSize(_ size: Size) -> Bool { + static public func isLargerThanScreenSize(_ size: Size) -> Bool { return size.rawValue < self.size().rawValue ? true : false; } @available(*, deprecated, message: "use < operator instead") - static open func isSmallerThanScreenSize(_ size: Size) -> Bool { + static public func isSmallerThanScreenSize(_ size: Size) -> Bool { return size.rawValue > self.size().rawValue ? true : false; } - static open func isRetina() -> Bool { + static public func isRetina() -> Bool { return UIScreen.main.scale > 1.0 } - static open func isPad() -> Bool { + static public func isPad() -> Bool { return type() == .iPad } - static open func isPhone() -> Bool { + static public func isPhone() -> Bool { return type() == .iPhone } - static open func isPod() -> Bool { + static public func isPod() -> Bool { return type() == .iPod } - static open func isSimulator() -> Bool { + static public func isSimulator() -> Bool { return type() == .simulator }