Skip to content

Commit

Permalink
Merged in Master
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Walsh committed Sep 21, 2017
1 parent 9e7aff8 commit dfc3b40
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 45 deletions.
4 changes: 2 additions & 2 deletions DeviceKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'DeviceKit'
s.version = '1.2.3'
s.version = '1.3.2'
s.summary = 'DeviceKit is a µ-framework that provides a value-type replacement of UIDevice.'

s.description = <<-DESC
Expand All @@ -17,7 +17,7 @@ Pod::Spec.new do |s|
s.tvos.deployment_target = '9.0'

s.source = { :git => 'https://github.com/dennisweissmann/DeviceKit.git', :tag => s.version }
s.source_files = 'Source'
s.source_files = 'Source/Device.generated.swift'

s.requires_arc = true
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Latest</string>
</dict>
<dict/>
</plist>
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
| Branch | Build Status | Versions |
|:---------|:--------------:|:----------:|
| **master** |[![Build Status](https://travis-ci.org/dennisweissmann/DeviceKit.svg?branch=master)](https://travis-ci.org/dennisweissmann/DeviceKit)| - |
| **Swift 3** |[![Build Status](https://travis-ci.org/dennisweissmann/DeviceKit.svg?branch=swift-3.0)](https://travis-ci.org/dennisweissmann/DeviceKit)| >= 1.0 |
| **Swift 4** |[![Build Status](https://travis-ci.org/dennisweissmann/DeviceKit.svg?branch=swift-4)](https://travis-ci.org/dennisweissmann/DeviceKit)| ≥ 1.3.0 |
| **Swift 3** |[![Build Status](https://travis-ci.org/dennisweissmann/DeviceKit.svg?branch=swift-3)](https://travis-ci.org/dennisweissmann/DeviceKit)| ≥ 1.0 ≤ 1.2.3 |
| **Swift 2.3** |[![Build Status](https://travis-ci.org/dennisweissmann/DeviceKit.svg?branch=swift-2.3-unsupported)](https://travis-ci.org/dennisweissmann/DeviceKit)| < 1.0 |

`DeviceKit` is a value-type replacement of [`UIDevice`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/).
Expand Down
49 changes: 12 additions & 37 deletions Source/Device.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ iPhones = [
Device("iPhone6sPlus", "Device is an [iPhone 6s Plus](https://support.apple.com/kb/SP727)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP727/SP727-iphone6s-plus-gray-select-2015.png", ["iPhone8,2"], 5.5, (9, 16), "iPhone 6s Plus", 401),
Device("iPhone7", "Device is an [iPhone 7](https://support.apple.com/kb/SP743)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP743/iphone7-black.png", ["iPhone9,1", "iPhone9,3"], 4.7, (9, 16), "iPhone 7", 326),
Device("iPhone7Plus", "Device is an [iPhone 7 Plus](https://support.apple.com/kb/SP744)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP744/iphone7-plus-black.png", ["iPhone9,2", "iPhone9,4"], 5.5, (9, 16), "iPhone 7 Plus", 401),
Device("iPhoneSE", "Device is an [iPhone SE](https://support.apple.com/kb/SP738)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP738/SP738.png", ["iPhone8,4"], 4, (9, 16), "iPhone SE", 326)
Device("iPhoneSE", "Device is an [iPhone SE](https://support.apple.com/kb/SP738)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP738/SP738.png", ["iPhone8,4"], 4, (9, 16), "iPhone SE", 326),
Device("iPhone8", "Device is an [iPhone 8](https://support.apple.com/kb/SP767)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP767/iphone8.png", ["iPhone10,4"], 4.7, (9, 16), "iPhone 8", 326),
Device("iPhone8Plus", "Device is an [iPhone 8 Plus](https://support.apple.com/kb/SP768)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP768/iphone8plus.png", ["iPhone10,5"], 5.5, (9, 16), "iPhone 8 Plus", 401),
Device("iPhoneX", "Device is an [iPhone X](https://support.apple.com/kb/SP770)", "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP770/iphonex.png", ["iPhone10,3"], 5.8, (9, 19.5), "iPhone X", 458)
]

iPads = [
Expand Down Expand Up @@ -72,7 +75,7 @@ import UIKit

// MARK: - Device

/// This enum is a value-type wrapper around and extension of
/// This enum is a value-type wrapper and extension of
/// [`UIDevice`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/).
///
/// Usage:
Expand Down Expand Up @@ -125,7 +128,7 @@ public enum Device {

/// Device is not yet known (implemented)
/// You can still use this enum as before but the description equals the identifier (you can get multiple identifiers for the same product class
/// (e.g. "iPhone6,1" or "iPhone 6,2" do both mean "iPhone 5s))
/// (e.g. "iPhone6,1" or "iPhone 6,2" do both mean "iPhone 5s"))
case unknown(String)

/// Initializes a `Device` representing the current device this software runs on.
Expand Down Expand Up @@ -209,12 +212,12 @@ public enum Device {

/// Returns whether the device is an iPhone (real or simulator)
public var isPhone: Bool {
return isOneOf(Device.allPhones) || isOneOf(Device.allSimulatorPhones)
return isOneOf(Device.allPhones) || isOneOf(Device.allSimulatorPhones) || UIDevice.current.userInterfaceIdiom == .phone
}

/// Returns whether the device is an iPad (real or simulator)
public var isPad: Bool {
return isOneOf(Device.allPads) || isOneOf(Device.allSimulatorPads)
return isOneOf(Device.allPads) || isOneOf(Device.allSimulatorPads) || UIDevice.current.userInterfaceIdiom == .pad
}

/// Returns whether the device is any of the simulator
Expand Down Expand Up @@ -286,7 +289,7 @@ public enum Device {
```
switch Device() {
case .iPodTouch5, .iPodTouch6: callMethodOnIPods()
case .iPhone4, iPhone4s, .iPhone5, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE: callMethodOnIPhones()
case .iPhone4, iPhone4s, .iPhone5, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX: callMethodOnIPhones()
case .iPad2, .iPad3, .iPad4, .iPadAir, .iPadAir2, .iPadMini, .iPadMini2, .iPadMini3, .iPadMini4, .iPadPro: callMethodOnIPads()
default: break
}
Expand All @@ -296,11 +299,11 @@ public enum Device {
```
let device = Device()
if device.isOneOf(Device.allPods) {
callMethodOnIPods()
callMethodOnIPods()
} else if device.isOneOf(Device.allPhones) {
callMethodOnIPhones()
callMethodOnIPhones()
} else if device.isOneOf(Device.allPads) {
callMethodOnIPads()
callMethodOnIPads()
}
```

Expand All @@ -312,34 +315,6 @@ public enum Device {
return devices.contains(self)
}

/// The style of interface to use on the current device.
/// This is pretty useless right now since it does not add any further functionality to the existing
/// [UIUserInterfaceIdiom](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/#//apple_ref/c/tdef/UIUserInterfaceIdiom) enum.
public enum UserInterfaceIdiom {

/// The user interface should be designed for iPhone and iPod touch.
case phone
/// The user interface should be designed for iPad.
case pad
/// The user interface should be designed for TV
case tv
/// The user interface should be designed for Car
case carPlay
/// Used when an object has a trait collection, but it is not in an environment yet. For example, a view that is created, but not put into a view hierarchy.
case unspecified

private init() {
switch UIDevice.current.userInterfaceIdiom {
case .pad: self = .pad
case .phone: self = .phone
case .tv: self = .tv
case .carPlay: self = .carPlay
default: self = .unspecified
}
}

}

/// The name identifying the device (e.g. "Dennis' iPhone").
public var name: String {
return UIDevice.current.name
Expand Down
2 changes: 1 addition & 1 deletion Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.2.3</string>
<string>1.3.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
18 changes: 18 additions & 0 deletions Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class DeviceKitTests: XCTestCase {
XCTAssertEqual(Device.mapToDevice(identifier: "iPhone9,2"), .iPhone7Plus)
XCTAssertEqual(Device.mapToDevice(identifier: "iPhone9,4"), .iPhone7Plus)
XCTAssertEqual(Device.mapToDevice(identifier: "iPhone8,4"), .iPhoneSE)
XCTAssertEqual(Device.mapToDevice(identifier: "iPhone10,4"), .iPhone8)
XCTAssertEqual(Device.mapToDevice(identifier: "iPhone10,5"), .iPhone8Plus)
XCTAssertEqual(Device.mapToDevice(identifier: "iPhone10,3"), .iPhoneX)
XCTAssertEqual(Device.mapToDevice(identifier: "iPad2,1"), .iPad2)
XCTAssertEqual(Device.mapToDevice(identifier: "iPad2,2"), .iPad2)
XCTAssertEqual(Device.mapToDevice(identifier: "iPad2,3"), .iPad2)
Expand Down Expand Up @@ -117,6 +120,9 @@ class DeviceKitTests: XCTestCase {
XCTAssertTrue(Device.iPhone7.screenRatio == (width: 9, height: 16))
XCTAssertTrue(Device.iPhone7Plus.screenRatio == (width: 9, height: 16))
XCTAssertTrue(Device.iPhoneSE.screenRatio == (width: 9, height: 16))
XCTAssertTrue(Device.iPhone8.screenRatio == (width: 9, height: 16))
XCTAssertTrue(Device.iPhone8Plus.screenRatio == (width: 9, height: 16))
XCTAssertTrue(Device.iPhoneX.screenRatio == (width: 9, height: 19.5))
XCTAssertTrue(Device.iPad2.screenRatio == (width: 3, height: 4))
XCTAssertTrue(Device.iPad3.screenRatio == (width: 3, height: 4))
XCTAssertTrue(Device.iPad4.screenRatio == (width: 3, height: 4))
Expand Down Expand Up @@ -149,10 +155,13 @@ class DeviceKitTests: XCTestCase {
XCTAssertEqual(Device.iPhone6.diagonal, 4.7)
XCTAssertEqual(Device.iPhone6s.diagonal, 4.7)
XCTAssertEqual(Device.iPhone7.diagonal, 4.7)
XCTAssertEqual(Device.iPhone8.diagonal, 4.7)

XCTAssertEqual(Device.iPhone6Plus.diagonal, 5.5)
XCTAssertEqual(Device.iPhone6sPlus.diagonal, 5.5)
XCTAssertEqual(Device.iPhone7Plus.diagonal, 5.5)
XCTAssertEqual(Device.iPhone8Plus.diagonal, 5.5)
XCTAssertEqual(Device.iPhoneX.diagonal, 5.8)

XCTAssertEqual(Device.iPad2.diagonal, 9.7)
XCTAssertEqual(Device.iPad3.diagonal, 9.7)
Expand Down Expand Up @@ -190,6 +199,9 @@ class DeviceKitTests: XCTestCase {
XCTAssertEqual(Device.iPhone7.description, "iPhone 7")
XCTAssertEqual(Device.iPhone7Plus.description, "iPhone 7 Plus")
XCTAssertEqual(Device.iPhoneSE.description, "iPhone SE")
XCTAssertEqual(Device.iPhone8.description, "iPhone 8")
XCTAssertEqual(Device.iPhone8Plus.description, "iPhone 8 Plus")
XCTAssertEqual(Device.iPhoneX.description, "iPhone X")
XCTAssertEqual(Device.iPad2.description, "iPad 2")
XCTAssertEqual(Device.iPad3.description, "iPad 3")
XCTAssertEqual(Device.iPad4.description, "iPad 4")
Expand Down Expand Up @@ -245,6 +257,12 @@ class DeviceKitTests: XCTestCase {
XCTAssertEqual(Device.iPhone7Plus.ppi, 401)
// source: https://en.wikipedia.org/wiki/IPhone_SE
XCTAssertEqual(Device.iPhoneSE.ppi, 326)
// source: https://en.wikipedia.org/wiki/IPhone_8
XCTAssertEqual(Device.iPhone8.ppi, 326)
// source: https://en.wikipedia.org/wiki/IPhone_8
XCTAssertEqual(Device.iPhone8Plus.ppi, 401)
// source: https://en.wikipedia.org/wiki/IPhone_X
XCTAssertEqual(Device.iPhoneX.ppi, 458)
// Ipads
// source: https://en.wikipedia.org/wiki/IPad_2
XCTAssertEqual(Device.iPad2.ppi, 132)
Expand Down

0 comments on commit dfc3b40

Please sign in to comment.