Skip to content

Commit

Permalink
Merge pull request #69 from nikans/master
Browse files Browse the repository at this point in the history
updated iphone and ipad models, added the '18 products, made compatible with Swift 4.2, updated readme and added some code completion comments
  • Loading branch information
Ekhoo authored Sep 25, 2018
2 parents 449a4a8 + 21f548b commit 4b5a3db
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 25 deletions.
8 changes: 4 additions & 4 deletions Device.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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";
};
Expand All @@ -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";
};
Expand Down
9 changes: 9 additions & 0 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ 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")
case .iPad2: print("It's an iPad 2")
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")
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,31 @@ 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")
case .iPad2: print("It's an iPad 2")
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")
case .iPadMini2: print("It's an iPad Mini 2")
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 ***/
Expand Down Expand Up @@ -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")
}
Expand Down
13 changes: 13 additions & 0 deletions Source/Size.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Source/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ public enum Version: String {
case iPhone8
case iPhone8Plus
case iPhoneX
case iPhoneXS
case iphoneXS_Max
case iphoneXR

/*** iPad ***/
case iPad1
case iPad2
case iPad3
case iPad4
case iPad5
case iPad6
case iPadAir
case iPadAir2
case iPadMini
Expand Down
48 changes: 27 additions & 21 deletions Source/iOS/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 4b5a3db

Please sign in to comment.