diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index d1b796e..f01e84d 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -628,6 +628,8 @@ public enum Device { case "i386", "x86_64", "arm64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "watchOS")) default: return unknown(identifier) } + #else + return unknown(identifier) #endif } @@ -879,6 +881,8 @@ public enum Device { } #elseif os(tvOS) return (width: -1, height: -1) + #else + return (width: -1, height: -1) #endif } @@ -1158,6 +1162,8 @@ public enum Device { return allTVs #elseif os(watchOS) return allWatches + #else + return [] #endif } @@ -1219,8 +1225,10 @@ public enum Device { guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().name - #else + #elseif canImport(UIKit) return UIDevice.current.name + #else + return nil #endif } @@ -1235,8 +1243,10 @@ public enum Device { } else { return UIDevice.current.systemName } - #else + #elseif canImport(UIKit) return UIDevice.current.systemName + #else + return nil #endif } @@ -1245,8 +1255,10 @@ public enum Device { guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().systemVersion - #else + #elseif canImport(UIKit) return UIDevice.current.systemVersion + #else + return nil #endif } @@ -1255,8 +1267,10 @@ public enum Device { guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().model - #else + #elseif canImport(UIKit) return UIDevice.current.model + #else + return nil #endif } @@ -1265,8 +1279,10 @@ public enum Device { guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().localizedModel - #else + #elseif canImport(UIKit) return UIDevice.current.localizedModel + #else + return nil #endif } @@ -1385,6 +1401,8 @@ public enum Device { } #elseif os(tvOS) return nil + #else + return nil #endif } @@ -1536,6 +1554,11 @@ extension Device: CustomStringConvertible { case .simulator(let model): return "Simulator (\(model.description))" case .unknown(let identifier): return identifier } + #else + switch self { + case .simulator(let model): return "Simulator (\(model.safeDescription))" + case .unknown(let identifier): return identifier + } #endif } @@ -1664,6 +1687,11 @@ extension Device: CustomStringConvertible { case .simulator(let model): return "Simulator (\(model.safeDescription))" case .unknown(let identifier): return identifier } + #else + switch self { + case .simulator(let model): return "Simulator (\(model.safeDescription))" + case .unknown(let identifier): return identifier + } #endif } @@ -2298,6 +2326,8 @@ extension Device { case .simulator(let model): return model.cpu case .unknown: return .unknown } + #else + return .unknown #endif } } @@ -2347,6 +2377,8 @@ extension Device.CPU: CustomStringConvertible { case .s9: return "S9" case .unknown: return "unknown" } + #else + return "unknown" #endif } } diff --git a/Source/Device.swift.gyb b/Source/Device.swift.gyb index 67cbb89..f5c7f6b 100644 --- a/Source/Device.swift.gyb +++ b/Source/Device.swift.gyb @@ -421,6 +421,8 @@ public enum Device { case "i386", "x86_64", "arm64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "watchOS")) default: return unknown(identifier) } + #else + return unknown(identifier) #endif } @@ -482,6 +484,8 @@ public enum Device { } #elseif os(tvOS) return (width: -1, height: -1) + #else + return (width: -1, height: -1) #endif } @@ -761,6 +765,8 @@ public enum Device { return allTVs #elseif os(watchOS) return allWatches + #else + return [] #endif } @@ -822,8 +828,10 @@ public enum Device { guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().name - #else + #elseif canImport(UIKit) return UIDevice.current.name + #else + return nil #endif } @@ -838,8 +846,10 @@ public enum Device { } else { return UIDevice.current.systemName } - #else + #elseif canImport(UIKit) return UIDevice.current.systemName + #else + return nil #endif } @@ -848,8 +858,10 @@ public enum Device { guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().systemVersion - #else + #elseif canImport(UIKit) return UIDevice.current.systemVersion + #else + return nil #endif } @@ -858,8 +870,10 @@ public enum Device { guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().model - #else + #elseif canImport(UIKit) return UIDevice.current.model + #else + return nil #endif } @@ -868,8 +882,10 @@ public enum Device { guard isCurrent else { return nil } #if os(watchOS) return WKInterfaceDevice.current().localizedModel - #else + #elseif canImport(UIKit) return UIDevice.current.localizedModel + #else + return nil #endif } @@ -893,6 +909,8 @@ public enum Device { } #elseif os(tvOS) return nil + #else + return nil #endif } @@ -948,6 +966,11 @@ extension Device: CustomStringConvertible { case .simulator(let model): return "Simulator (\(model.description))" case .unknown(let identifier): return identifier } + #else + switch self { + case .simulator(let model): return "Simulator (\(model.safeDescription))" + case .unknown(let identifier): return identifier + } #endif } @@ -980,6 +1003,11 @@ extension Device: CustomStringConvertible { case .simulator(let model): return "Simulator (\(model.safeDescription))" case .unknown(let identifier): return identifier } + #else + switch self { + case .simulator(let model): return "Simulator (\(model.safeDescription))" + case .unknown(let identifier): return identifier + } #endif } @@ -1468,6 +1496,8 @@ extension Device { case .simulator(let model): return model.cpu case .unknown: return .unknown } + #else + return .unknown #endif } } @@ -1490,6 +1520,8 @@ extension Device.CPU: CustomStringConvertible { % end case .unknown: return "unknown" } + #else + return "unknown" #endif } } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 5f53584..bf0bf16 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -17,20 +17,31 @@ class DeviceKitTests: XCTestCase { let device = Device.current func testDeviceSimulator() { + #if os(macOS) + XCTAssertFalse(device.isOneOf(Device.allSimulators)) + #else XCTAssertTrue(device.isOneOf(Device.allSimulators)) + #endif } func testIsSimulator() { + #if os(macOS) + XCTAssertFalse(device.isSimulator) + #else XCTAssertTrue(device.isSimulator) + #endif } func testDeviceDescription() { + #if os(macOS) + #else XCTAssertTrue(device.description.hasPrefix("Simulator")) XCTAssertTrue(device.description.contains("iPhone") || device.description.contains("iPad") || device.description.contains("iPod") || device.description.contains("TV") || device.description.contains("Apple Watch")) + #endif } func testIsCanvas() { @@ -40,6 +51,8 @@ class DeviceKitTests: XCTestCase { let otherDevice: Device = device == .appleTVHD ? .appleTV4K : .appleTVHD #elseif os(watchOS) let otherDevice: Device = device == .appleWatchUltra ? .appleWatchSeries8_41mm : .appleWatchUltra + #else + let otherDevice: Device = .unknown("mac") #endif XCTAssertEqual(otherDevice.isCanvas, nil) XCTAssertEqual(device.isCanvas, false)