diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml
index ce48216..4b145e9 100644
--- a/.github/workflows/swift.yml
+++ b/.github/workflows/swift.yml
@@ -10,5 +10,7 @@ jobs:
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- - name: Test
+ - name: Test (iOS)
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "UIDeviceComplete.xcodeproj" -scheme "UIDeviceComplete" -destination "OS=16.0,name=iPhone 14 Pro" clean test | xcpretty
+ - name: Test (watchOS)
+ run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project "UIDeviceComplete.xcodeproj" -scheme "UIDeviceComplete" -destination "OS=9.0,name=Apple Watch Series 8 (45mm)" clean test | xcpretty
diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000..919434a
--- /dev/null
+++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/Package.swift b/Package.swift
index 3ac5ed8..4e31a0b 100644
--- a/Package.swift
+++ b/Package.swift
@@ -25,7 +25,7 @@ import PackageDescription
let package = Package(
name: "UIDeviceComplete",
platforms: [
- .iOS(.v11)
+ .iOS(.v11), .watchOS(.v4)
],
products: [
.library(name: "UIDeviceComplete", targets: ["UIDeviceComplete"])
diff --git a/Sources/DeviceFamily.swift b/Sources/DeviceFamily.swift
index 30fc5d7..93911bc 100644
--- a/Sources/DeviceFamily.swift
+++ b/Sources/DeviceFamily.swift
@@ -26,6 +26,7 @@ public enum DeviceFamily: String {
case iPhone
case iPod
case iPad
+ case watch
case unknown
public init(rawValue: String) {
@@ -36,6 +37,8 @@ public enum DeviceFamily: String {
self = .iPod
case "iPad":
self = .iPad
+ case "Watch":
+ self = .watch
default:
self = .unknown
}
diff --git a/Sources/DeviceModel.swift b/Sources/DeviceModel.swift
index c9b5682..96ca16b 100644
--- a/Sources/DeviceModel.swift
+++ b/Sources/DeviceModel.swift
@@ -23,6 +23,7 @@
public enum DeviceModel: CaseIterable {
+ #if os(iOS)
case iPhone4, iPhone4S
case iPhone5, iPhone5C, iPhone5S
case iPhone6, iPhone6Plus
@@ -62,7 +63,24 @@ public enum DeviceModel: CaseIterable {
case iPodTouchFirstGen, iPodTouchSecondGen, iPodTouchThirdGen,
iPodTouchFourthGen, iPodTouchFifthGen, iPodTouchSixthGen, iPodTouchSeventhGen
-
+
+ #elseif os(watchOS)
+ case firstGen
+ case series1
+ case series2
+ case series3
+ case series4
+ case series5
+ case se
+ case series6
+ case series7
+ case series8
+ case se2
+ case ultra
+ case series9
+ case ultra2
+ #endif
+
case unknown
}
@@ -72,19 +90,24 @@ public enum DeviceModel: CaseIterable {
extension DeviceModel {
init(identifier: Identifier) {
switch identifier.type {
+ #if os(iOS)
case .iPhone:
self = DeviceModel.detectIphoneModel(with: identifier)
case .iPad:
self = DeviceModel.detectIpadModel(with: identifier)
case .iPod:
self = DeviceModel.detectIpodModel(with: identifier)
+ #elseif os(watchOS)
+ case .watch:
+ self = DeviceModel.detectWatchModel(with: identifier)
+ #endif
default:
self = .unknown
}
}
}
-
+#if os(iOS)
// MARK: Detecting iPhone Models
extension DeviceModel {
@@ -154,8 +177,9 @@ extension DeviceModel {
}
}
}
+#endif
-
+#if os(iOS)
// MARK: Detecting iPad Models
extension DeviceModel {
@@ -207,8 +231,9 @@ extension DeviceModel {
}
}
}
+#endif
-
+#if os(iOS)
// MARK: Detecting iPod Models
extension DeviceModel {
@@ -230,8 +255,40 @@ extension DeviceModel {
}
}
}
+#endif
+#if os(watchOS)
+// MARK: Detecting Apple Watch Models
+
+extension DeviceModel {
+ fileprivate static func detectWatchModel(with identifier: Identifier) -> DeviceModel {
+ guard let major = identifier.version.major,
+ let minor = identifier.version.minor
+ else { return .unknown }
+
+ switch (major, minor) {
+ case (1, _): return .firstGen
+ case (2, 3), (2, 4): return .series2
+ case (2, 6), (2, 7): return .series1
+ case (3, _): return .series3
+ case (4, _): return .series4
+ case (5, 1), (5, 2), (5, 3), (5, 4): return .series5
+ case (5, 9), (5, 10), (5, 11), (5, 12): return .se
+ case (6, 1), (6, 2), (6, 3), (6, 4): return .series6
+ case (6, 6), (6, 7), (6, 8), (6, 9): return .series7
+ case (6, 10), (6, 11), (6, 12), (6, 13): return .se2
+ case (6, 14), (6, 15), (6, 16), (6, 17): return .series8
+ case (6, 18): return .ultra
+ case (7, 1), (7, 2), (7, 3), (7, 4): return .series9
+ case (7, 5): return .ultra2
+
+ default: return .unknown
+ }
+ }
+}
+#endif
+#if os(iOS)
// MARK: Detecting the Notch
extension DeviceModel {
@@ -266,3 +323,4 @@ extension DeviceModel {
}
}
}
+#endif
diff --git a/Sources/Identifier.swift b/Sources/Identifier.swift
index ff73c67..20e5f84 100644
--- a/Sources/Identifier.swift
+++ b/Sources/Identifier.swift
@@ -69,6 +69,8 @@ extension Identifier: CustomStringConvertible {
return iPadStringRepresentation(major: major, minor: minor)
case .iPod:
return iPodStringRepresentation(major: major, minor: minor)
+ case .watch:
+ return watchStringRepresentable(major: major, minor: minor)
case .unknown:
return "unknown"
}
@@ -384,4 +386,99 @@ extension Identifier: CustomStringConvertible {
return "unknown"
}
}
+
+ private func watchStringRepresentable(major: Int, minor: Int) -> String {
+ switch (major, minor) {
+ case (1, 1):
+ return "Apple Watch (1st generation), 38mm case"
+ case (1, 2):
+ return "Apple Watch (1st generation), 42mm case"
+ case (2, 3):
+ return "Apple Watch Series 2, 38mm case"
+ case (2, 4):
+ return "Apple Watch Series 2, 42mm case"
+ case (2, 6):
+ return "Apple Watch Series 1, 38mm case"
+ case (2, 7):
+ return "Apple Watch Series 1, 42mm case"
+ case (3, 1):
+ return "Apple Watch Series 3, 38mm case (GPS + Cellular)"
+ case (3, 2):
+ return "Apple Watch Series 3, 42mm case (GPS + Cellular)"
+ case (3, 3):
+ return "Apple Watch Series 3, 38mm case (GPS)"
+ case (3, 4):
+ return "Apple Watch Series 3, 42mm case (GPS)"
+ case (4, 1):
+ return "Apple Watch Series 4, 40mm case (GPS)"
+ case (4, 2):
+ return "Apple Watch Series 4, 44mm case (GPS)"
+ case (4, 3):
+ return "Apple Watch Series 4, 40mm case (GPS + Cellular)"
+ case (4, 4):
+ return "Apple Watch Series 4, 44mm case (GPS + Cellular)"
+ case (5, 1):
+ return "Apple Watch Series 5, 40mm case (GPS)"
+ case (5, 2):
+ return "Apple Watch Series 5, 44mm case (GPS)"
+ case (5, 3):
+ return "Apple Watch Series 5, 40mm case (GPS + Cellular)"
+ case (5, 4):
+ return "Apple Watch Series 5, 44mm case (GPS + Cellular)"
+ case (5, 9):
+ return "Apple Watch SE, 40mm case (GPS)"
+ case (5, 10):
+ return "Apple Watch SE, 44mm case (GPS)"
+ case (5, 11):
+ return "Apple Watch SE, 40mm case (GPS + Cellular)"
+ case (5, 12):
+ return "Apple Watch SE, 44mm case (GPS + Cellular)"
+ case (6, 1):
+ return "Apple Watch Series 6, 40mm case (GPS)"
+ case (6, 2):
+ return "Apple Watch Series 6, 44mm case (GPS)"
+ case (6, 3):
+ return "Apple Watch Series 6, 40mm case (GPS + Cellular)"
+ case (6, 4):
+ return "Apple Watch Series 6, 44mm case (GPS + Cellular)"
+ case (6, 6):
+ return "Apple Watch Series 7, 41mm case (GPS)"
+ case (6, 7):
+ return "Apple Watch Series 7, 45mm case (GPS)"
+ case (6, 8):
+ return "Apple Watch Series 7, 41mm case (GPS + Cellular)"
+ case (6, 9):
+ return "Apple Watch Series 7, 45mm case (GPS + Cellular)"
+ case (6, 10):
+ return "Apple Watch SE (2nd Generation), 40mm case (GPS)"
+ case (6, 11):
+ return "Apple Watch SE (2nd Generation), 44mm case (GPS)"
+ case (6, 12):
+ return "Apple Watch SE (2nd Generation), 40mm case (GPS + Cellular)"
+ case (6, 13):
+ return "Apple Watch SE (2nd Generation), 44mm case (GPS + Cellular)"
+ case (6, 14):
+ return "Apple Watch Series 8, 41mm case (GPS)"
+ case (6, 15):
+ return "Apple Watch Series 8, 45mm case (GPS)"
+ case (6, 16):
+ return "Apple Watch Series 8, 41mm case (GPS + Cellular)"
+ case (6, 17):
+ return "Apple Watch Series 8, 45mm case (GPS + Cellular)"
+ case (6, 18):
+ return "Apple Watch Ultra"
+ case (7, 1):
+ return "Apple Watch Series 9, 41mm case (GPS)"
+ case (7, 2):
+ return "Apple Watch Series 9, 45mm case (GPS)"
+ case (7, 3):
+ return "Apple Watch Series 9, 41mm case (GPS + Cellular)"
+ case (7, 4):
+ return "Apple Watch Series 9, 45mm case (GPS + Cellular)"
+ case (7, 5):
+ return "Apple Watch Ultra 2"
+ default:
+ return "unknown"
+ }
+ }
}
diff --git a/Sources/Screen.swift b/Sources/Screen.swift
index 5534a67..f6b9175 100644
--- a/Sources/Screen.swift
+++ b/Sources/Screen.swift
@@ -21,9 +21,12 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
+#if os(iOS)
import UIKit
+#endif
public struct Screen {
+ #if os(iOS)
init(width: Double, height: Double, scale: Double) {
self.width = width
self.height = height
@@ -37,9 +40,16 @@ public struct Screen {
public var adjustedScale: Double {
return 1.0 / scale
}
+ #elseif os(watchOS)
+ init(identifier: Identifier) {
+ self.identifier = identifier
+ }
+
+ let identifier: Identifier
+ #endif
}
-
+#if os(iOS)
// MARK: - Detecting Screen size in Inches
extension Screen {
@@ -89,3 +99,33 @@ extension Screen {
}
}
+#endif
+
+#if os(watchOS)
+extension Screen {
+ public var caseSize: Int? {
+ guard let major = identifier.version.major,
+ let minor = identifier.version.minor
+ else { return nil }
+
+ switch (major, minor) {
+ case (1, 1), (2, 3), (2, 6), (3, 1), (3, 3): return 38
+ case (1, 2), (2, 4), (2, 7), (3, 2), (3, 4): return 42
+
+ case (4, 1), (4, 3), (5, 1), (5, 3), (5, 9),
+ (5, 11), (6, 1), (6, 3), (6, 10), (6, 12): return 40
+ case (4, 2), (4, 4), (5, 2), (5, 4), (5, 10),
+ (5, 12), (6, 2), (6, 4), (6, 11), (6, 13): return 44
+
+ case (6, 6), (6, 8), (6, 14), (6, 16),
+ (7, 1), (7, 3): return 41
+ case (6, 7), (6, 9), (6, 15), (6, 17),
+ (7, 2), (7, 4): return 45
+
+ case (6, 18), (7, 5): return 49
+
+ default: return nil
+ }
+ }
+}
+#endif
diff --git a/Sources/UIDeviceComplete.swift b/Sources/UIDeviceComplete.swift
index c84baa7..f95503f 100644
--- a/Sources/UIDeviceComplete.swift
+++ b/Sources/UIDeviceComplete.swift
@@ -21,7 +21,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
+#if os(iOS)
import UIKit
+#elseif os(watchOS)
+import WatchKit
+#endif
public final class UIDeviceComplete {
let base: Base
@@ -42,4 +46,8 @@ public extension UIDeviceCompleteCompatible {
}
}
+#if os(iOS)
extension UIDevice: UIDeviceCompleteCompatible { }
+#elseif os(watchOS)
+extension WKInterfaceDevice: UIDeviceCompleteCompatible { }
+#endif
diff --git a/Sources/UIDeviceExtensions.swift b/Sources/UIDeviceExtensions.swift
index fa996ac..a70babd 100644
--- a/Sources/UIDeviceExtensions.swift
+++ b/Sources/UIDeviceExtensions.swift
@@ -21,9 +21,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
+#if os(iOS)
import UIKit
+public typealias DCDevice = UIDevice
+#elseif os(watchOS)
+import WatchKit
+public typealias DCDevice = WKInterfaceDevice
+#endif
-public extension UIDeviceComplete where Base == UIDevice {
+public extension UIDeviceComplete where Base == DCDevice {
private var identifier: Identifier? {
return System.name.flatMap {
@@ -45,7 +51,8 @@ public extension UIDeviceComplete where Base == UIDevice {
var commonDeviceName: String {
return identifier?.description ?? "unknown"
}
-
+
+ #if os(iOS)
/// Device family iPhone
var isIphone: Bool {
return deviceFamily == .iPhone
@@ -60,13 +67,14 @@ public extension UIDeviceComplete where Base == UIDevice {
var isIpod: Bool {
return deviceFamily == .iPod
}
-
+ #endif
+
}
-
+#if os(iOS)
// MARK: - Screen Size Detection
-public extension UIDeviceComplete where Base == UIDevice {
+public extension UIDeviceComplete where Base == DCDevice {
var screenSize: Screen {
let scale: Double = Double(UIScreen.main.scale)
let width: Double = Double(UIScreen.main.bounds.width)
@@ -75,3 +83,4 @@ public extension UIDeviceComplete where Base == UIDevice {
return Screen(width: width, height: height, scale: scale)
}
}
+#endif
diff --git a/Tests/DeviceFamilyTests.swift b/Tests/DeviceFamilyTests.swift
index f4cc8d6..8d617f6 100644
--- a/Tests/DeviceFamilyTests.swift
+++ b/Tests/DeviceFamilyTests.swift
@@ -41,6 +41,11 @@ class DeviceFamilyTests: XCTestCase {
XCTAssert(deviceFamily == .iPad, "DeviceFamily - .iPad is failing")
}
+ func testDeviceFamilyWatch() {
+ let deviceFamily = DeviceFamily(rawValue: "Watch")
+ XCTAssert(deviceFamily == .watch, "DeviceFamily - .watch is failing")
+ }
+
func testInvalidDeviceFamily() {
let deviceFamily = DeviceFamily(rawValue: "Apple II")
XCTAssert(deviceFamily == .unknown, "DeviceFamily - .unknown is failing")
@@ -54,5 +59,5 @@ class DeviceFamilyTests: XCTestCase {
XCTAssert(!(deviceFamily.isSimulator), "DeviceFamily - .isSimulator is failing")
#endif
}
-
+
}
diff --git a/Tests/DeviceModelTests.swift b/Tests/DeviceModelTests.swift
index 8c8d7d8..020e47c 100644
--- a/Tests/DeviceModelTests.swift
+++ b/Tests/DeviceModelTests.swift
@@ -28,6 +28,7 @@ import XCTest
class DeviceModelTests: XCTestCase {
+ #if os(iOS)
// MARK: - iPhone Device Model tests
func testDeviceModelIPhone4() {
@@ -511,4 +512,140 @@ class DeviceModelTests: XCTestCase {
withModels.forEach { XCTAssertTrue($0.hasDynamicIsland) }
withoutModels.forEach { XCTAssertFalse($0.hasDynamicIsland) }
}
+ #endif
+
+ #if os(watchOS)
+ // MARK: - Apple Watch Model tests
+
+ func testDeviceModelWatchFirstGen() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch1,1"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch1,2"))
+ XCTAssert(deviceModel1 == .firstGen, "DeviceModel - .firstGen is failing")
+ XCTAssert(deviceModel2 == .firstGen, "DeviceModel - .firstGen is failing")
+ }
+
+ func testDeviceModelWatchSeries1() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch2,6"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch2,7"))
+ XCTAssert(deviceModel1 == .series1, "DeviceModel - .series1 is failing")
+ XCTAssert(deviceModel2 == .series1, "DeviceModel - .series1 is failing")
+ }
+
+ func testDeviceModelWatchSeries2() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch2,3"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch2,4"))
+ XCTAssert(deviceModel1 == .series2, "DeviceModel - .series2 is failing")
+ XCTAssert(deviceModel2 == .series2, "DeviceModel - .series2 is failing")
+ }
+
+ func testDeviceModelWatchSeries3() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch3,1"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch3,2"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch3,3"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch3,4"))
+ XCTAssert(deviceModel1 == .series3, "DeviceModel - .series3 is failing")
+ XCTAssert(deviceModel2 == .series3, "DeviceModel - .series3 is failing")
+ XCTAssert(deviceModel3 == .series3, "DeviceModel - .series3 is failing")
+ XCTAssert(deviceModel4 == .series3, "DeviceModel - .series3 is failing")
+ }
+
+ func testDeviceModelWatchSeries4() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch4,1"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch4,2"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch4,3"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch4,4"))
+ XCTAssert(deviceModel1 == .series4, "DeviceModel - .series4 is failing")
+ XCTAssert(deviceModel2 == .series4, "DeviceModel - .series4 is failing")
+ XCTAssert(deviceModel3 == .series4, "DeviceModel - .series4 is failing")
+ XCTAssert(deviceModel4 == .series4, "DeviceModel - .series4 is failing")
+ }
+
+ func testDeviceModelWatchSeries5() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch5,1"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch5,2"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch5,3"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch5,4"))
+ XCTAssert(deviceModel1 == .series5, "DeviceModel - .series5 is failing")
+ XCTAssert(deviceModel2 == .series5, "DeviceModel - .series5 is failing")
+ XCTAssert(deviceModel3 == .series5, "DeviceModel - .series5 is failing")
+ XCTAssert(deviceModel4 == .series5, "DeviceModel - .series5 is failing")
+ }
+
+ func testDeviceModelWatchSE() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch5,9"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch5,10"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch5,11"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch5,12"))
+ XCTAssert(deviceModel1 == .se, "DeviceModel - .se is failing")
+ XCTAssert(deviceModel2 == .se, "DeviceModel - .se is failing")
+ XCTAssert(deviceModel3 == .se, "DeviceModel - .se is failing")
+ XCTAssert(deviceModel4 == .se, "DeviceModel - .se is failing")
+ }
+
+ func testDeviceModelWatchSeries6() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch6,1"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch6,2"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch6,3"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch6,4"))
+ XCTAssert(deviceModel1 == .series6, "DeviceModel - .series6 is failing")
+ XCTAssert(deviceModel2 == .series6, "DeviceModel - .series6 is failing")
+ XCTAssert(deviceModel3 == .series6, "DeviceModel - .series6 is failing")
+ XCTAssert(deviceModel4 == .series6, "DeviceModel - .series6 is failing")
+ }
+
+ func testDeviceModelWatchSeries7() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch6,6"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch6,7"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch6,8"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch6,9"))
+ XCTAssert(deviceModel1 == .series7, "DeviceModel - .series7 is failing")
+ XCTAssert(deviceModel2 == .series7, "DeviceModel - .series7 is failing")
+ XCTAssert(deviceModel3 == .series7, "DeviceModel - .series7 is failing")
+ XCTAssert(deviceModel4 == .series7, "DeviceModel - .series7 is failing")
+ }
+
+ func testDeviceModelWatchSE2() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch6,10"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch6,11"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch6,12"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch6,13"))
+ XCTAssert(deviceModel1 == .se2, "DeviceModel - .se2 is failing")
+ XCTAssert(deviceModel2 == .se2, "DeviceModel - .se2 is failing")
+ XCTAssert(deviceModel3 == .se2, "DeviceModel - .se2 is failing")
+ XCTAssert(deviceModel4 == .se2, "DeviceModel - .se2 is failing")
+ }
+
+ func testDeviceModelWatchSeries8() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch6,14"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch6,15"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch6,16"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch6,17"))
+ XCTAssert(deviceModel1 == .series8, "DeviceModel - .series8 is failing")
+ XCTAssert(deviceModel2 == .series8, "DeviceModel - .series8 is failing")
+ XCTAssert(deviceModel3 == .series8, "DeviceModel - .series8 is failing")
+ XCTAssert(deviceModel4 == .series8, "DeviceModel - .series8 is failing")
+ }
+
+ func testDeviceModelWatchUltra() {
+ let deviceModel = DeviceModel(identifier: Identifier("Watch6,18"))
+ XCTAssert(deviceModel == .ultra, "DeviceModel - .ultra is failing")
+ }
+
+ func testDeviceModelWatchSeries9() {
+ let deviceModel1 = DeviceModel(identifier: Identifier("Watch7,1"))
+ let deviceModel2 = DeviceModel(identifier: Identifier("Watch7,2"))
+ let deviceModel3 = DeviceModel(identifier: Identifier("Watch7,3"))
+ let deviceModel4 = DeviceModel(identifier: Identifier("Watch7,4"))
+ XCTAssert(deviceModel1 == .series9, "DeviceModel - .series9 is failing")
+ XCTAssert(deviceModel2 == .series9, "DeviceModel - .series9 is failing")
+ XCTAssert(deviceModel3 == .series9, "DeviceModel - .series9 is failing")
+ XCTAssert(deviceModel4 == .series9, "DeviceModel - .series9 is failing")
+ }
+
+ func testDeviceModelWatchUltra2() {
+ let deviceModel = DeviceModel(identifier: Identifier("Watch7,5"))
+ XCTAssert(deviceModel == .ultra2, "DeviceModel - .ultra2 is failing")
+ }
+
+ #endif
}
diff --git a/Tests/IdentifierTests.swift b/Tests/IdentifierTests.swift
index 1369805..dd37292 100644
--- a/Tests/IdentifierTests.swift
+++ b/Tests/IdentifierTests.swift
@@ -63,7 +63,7 @@ class IdentifierTests: XCTestCase {
)
}
-
+ #if os(iOS)
// MARK: - iPhone String Description tests
func testDisplayStringiPhone16v2() {
@@ -611,4 +611,184 @@ class IdentifierTests: XCTestCase {
func testDisplayStringiPad1v1() {
XCTAssert(Identifier("iPad1,1").description == "iPad", "iPad1,1 is failing to produce a common device model string")
}
+ #endif
+
+ #if os(watchOS)
+ func testDisplayStringWatch1v1() {
+ XCTAssert(Identifier("Watch1,1").description == "Apple Watch (1st generation), 38mm case", "Watch1,1 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch1v2() {
+ XCTAssert(Identifier("Watch1,2").description == "Apple Watch (1st generation), 42mm case", "Watch1,2 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch2v3() {
+ XCTAssert(Identifier("Watch2,3").description == "Apple Watch Series 2, 38mm case", "Watch2,3 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch2v4() {
+ XCTAssert(Identifier("Watch2,4").description == "Apple Watch Series 2, 42mm case", "Watch2,4 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch2v6() {
+ XCTAssert(Identifier("Watch2,6").description == "Apple Watch Series 1, 38mm case", "Watch2,6 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch2v7() {
+ XCTAssert(Identifier("Watch2,7").description == "Apple Watch Series 1, 42mm case", "Watch2,7 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch3v1() {
+ XCTAssert(Identifier("Watch3,1").description == "Apple Watch Series 3, 38mm case (GPS + Cellular)", "Watch3,1 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch3v2() {
+ XCTAssert(Identifier("Watch3,2").description == "Apple Watch Series 3, 42mm case (GPS + Cellular)", "Watch3,2 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch3v3() {
+ XCTAssert(Identifier("Watch3,3").description == "Apple Watch Series 3, 38mm case (GPS)", "Watch3,3 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch3v4() {
+ XCTAssert(Identifier("Watch3,4").description == "Apple Watch Series 3, 42mm case (GPS)", "Watch3,4 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch4v1() {
+ XCTAssert(Identifier("Watch4,1").description == "Apple Watch Series 4, 40mm case (GPS)", "Watch4,1 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch4v2() {
+ XCTAssert(Identifier("Watch4,2").description == "Apple Watch Series 4, 44mm case (GPS)", "Watch4,2 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch4v3() {
+ XCTAssert(Identifier("Watch4,3").description == "Apple Watch Series 4, 40mm case (GPS + Cellular)", "Watch4,3 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch4v4() {
+ XCTAssert(Identifier("Watch4,4").description == "Apple Watch Series 4, 44mm case (GPS + Cellular)", "Watch4,4 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch5v1() {
+ XCTAssert(Identifier("Watch5,1").description == "Apple Watch Series 5, 40mm case (GPS)", "Watch5,1 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch5v2() {
+ XCTAssert(Identifier("Watch5,2").description == "Apple Watch Series 5, 44mm case (GPS)", "Watch5,2 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch5v3() {
+ XCTAssert(Identifier("Watch5,3").description == "Apple Watch Series 5, 40mm case (GPS + Cellular)", "Watch5,3 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch5v4() {
+ XCTAssert(Identifier("Watch5,4").description == "Apple Watch Series 5, 44mm case (GPS + Cellular)", "Watch5,4 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch5v9() {
+ XCTAssert(Identifier("Watch5,9").description == "Apple Watch SE, 40mm case (GPS)", "Watch5,9 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch5v10() {
+ XCTAssert(Identifier("Watch5,10").description == "Apple Watch SE, 44mm case (GPS)", "Watch5,10 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch5v11() {
+ XCTAssert(Identifier("Watch5,11").description == "Apple Watch SE, 40mm case (GPS + Cellular)", "Watch5,11 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch5v12() {
+ XCTAssert(Identifier("Watch5,12").description == "Apple Watch SE, 44mm case (GPS + Cellular)", "Watch5,12 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v1() {
+ XCTAssert(Identifier("Watch6,1").description == "Apple Watch Series 6, 40mm case (GPS)", "Watch6,1 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v2() {
+ XCTAssert(Identifier("Watch6,2").description == "Apple Watch Series 6, 44mm case (GPS)", "Watch6,2 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v3() {
+ XCTAssert(Identifier("Watch6,3").description == "Apple Watch Series 6, 40mm case (GPS + Cellular)", "Watch6,3 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v4() {
+ XCTAssert(Identifier("Watch6,4").description == "Apple Watch Series 6, 44mm case (GPS + Cellular)", "Watch6,4 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v6() {
+ XCTAssert(Identifier("Watch6,6").description == "Apple Watch Series 7, 41mm case (GPS)", "Watch6,6 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v7() {
+ XCTAssert(Identifier("Watch6,7").description == "Apple Watch Series 7, 45mm case (GPS)", "Watch6,7 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v8() {
+ XCTAssert(Identifier("Watch6,8").description == "Apple Watch Series 7, 41mm case (GPS + Cellular)", "Watch6,8 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v9() {
+ XCTAssert(Identifier("Watch6,9").description == "Apple Watch Series 7, 45mm case (GPS + Cellular)", "Watch6,9 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v10() {
+ XCTAssert(Identifier("Watch6,10").description == "Apple Watch SE (2nd Generation), 40mm case (GPS)", "Watch6,10 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v11() {
+ XCTAssert(Identifier("Watch6,11").description == "Apple Watch SE (2nd Generation), 44mm case (GPS)", "Watch6,11 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v12() {
+ XCTAssert(Identifier("Watch6,12").description == "Apple Watch SE (2nd Generation), 40mm case (GPS + Cellular)", "Watch6,12 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v13() {
+ XCTAssert(Identifier("Watch6,13").description == "Apple Watch SE (2nd Generation), 44mm case (GPS + Cellular)", "Watch6,13 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v14() {
+ XCTAssert(Identifier("Watch6,14").description == "Apple Watch Series 8, 41mm case (GPS)", "Watch6,14 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v15() {
+ XCTAssert(Identifier("Watch6,15").description == "Apple Watch Series 8, 45mm case (GPS)", "Watch6,15 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v16() {
+ XCTAssert(Identifier("Watch6,16").description == "Apple Watch Series 8, 41mm case (GPS + Cellular)", "Watch6,16 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v17() {
+ XCTAssert(Identifier("Watch6,17").description == "Apple Watch Series 8, 45mm case (GPS + Cellular)", "Watch6,17 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch6v18() {
+ XCTAssert(Identifier("Watch6,18").description == "Apple Watch Ultra", "Watch6,18 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch7v1() {
+ XCTAssert(Identifier("Watch7,1").description == "Apple Watch Series 9, 41mm case (GPS)", "Watch7,1 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch7v2() {
+ XCTAssert(Identifier("Watch7,2").description == "Apple Watch Series 9, 45mm case (GPS)", "Watch7,2 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch7v3() {
+ XCTAssert(Identifier("Watch7,3").description == "Apple Watch Series 9, 41mm case (GPS + Cellular)", "Watch7,3 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch7v4() {
+ XCTAssert(Identifier("Watch7,4").description == "Apple Watch Series 9, 45mm case (GPS + Cellular)", "Watch7,4 is failing to produce a common device model string")
+ }
+
+ func testDisplayStringWatch7v5() {
+ XCTAssert(Identifier("Watch7,5").description == "Apple Watch Ultra 2", "Watch7,5 is failing to produce a common device model string")
+ }
+
+ #endif
}
diff --git a/Tests/UIDeviceExtensionsTests.swift b/Tests/UIDeviceExtensionsTests.swift
index f53d6b9..543b1cc 100644
--- a/Tests/UIDeviceExtensionsTests.swift
+++ b/Tests/UIDeviceExtensionsTests.swift
@@ -24,9 +24,17 @@
@testable import UIDeviceComplete
import XCTest
+#if os(watchOS)
+import WatchKit
+#endif
+
class UIDeviceExtensionsTests: XCTestCase {
+ #if os(iOS)
let DeviceExtensions = UIDeviceComplete(UIDevice())
+ #elseif os(watchOS)
+ let DeviceExtensions = UIDeviceComplete(WKInterfaceDevice())
+ #endif
func testDeviceExtensionsDeviceFamily() {
XCTAssertNotEqual(.unknown, DeviceExtensions.deviceFamily, "DeviceExtensions - .deviceFamily is failing")
diff --git a/UIDeviceComplete.xcodeproj/project.pbxproj b/UIDeviceComplete.xcodeproj/project.pbxproj
index 009e021..5b1fc17 100644
--- a/UIDeviceComplete.xcodeproj/project.pbxproj
+++ b/UIDeviceComplete.xcodeproj/project.pbxproj
@@ -412,10 +412,12 @@
PRODUCT_BUNDLE_IDENTIFIER = nmaccharoli.UIDeviceComplete;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
+ SUPPORTED_PLATFORMS = "iphoneos iphonesimulator watchos watchsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
- TARGETED_DEVICE_FAMILY = "1,2";
+ TARGETED_DEVICE_FAMILY = "1,2,4";
+ WATCHOS_DEPLOYMENT_TARGET = 4.0;
};
name = Debug;
};
@@ -436,9 +438,11 @@
PRODUCT_BUNDLE_IDENTIFIER = nmaccharoli.UIDeviceComplete;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
+ SUPPORTED_PLATFORMS = "iphoneos iphonesimulator watchos watchsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_VERSION = 5.0;
- TARGETED_DEVICE_FAMILY = "1,2";
+ TARGETED_DEVICE_FAMILY = "1,2,4";
+ WATCHOS_DEPLOYMENT_TARGET = 4.0;
};
name = Release;
};
@@ -454,8 +458,12 @@
PRODUCT_BUNDLE_IDENTIFIER = nmaccharoli.UIDeviceCompleteTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
+ SUPPORTED_PLATFORMS = "iphoneos iphonesimulator watchos watchsimulator";
+ SUPPORTS_MACCATALYST = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2,4";
+ WATCHOS_DEPLOYMENT_TARGET = 4.0;
};
name = Debug;
};
@@ -471,7 +479,11 @@
PRODUCT_BUNDLE_IDENTIFIER = nmaccharoli.UIDeviceCompleteTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
+ SUPPORTED_PLATFORMS = "iphoneos iphonesimulator watchos watchsimulator";
+ SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2,4";
+ WATCHOS_DEPLOYMENT_TARGET = 4.0;
};
name = Release;
};