Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes macOS build #379

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions Source/Device.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -879,6 +881,8 @@ public enum Device {
}
#elseif os(tvOS)
return (width: -1, height: -1)
#else
return (width: -1, height: -1)
#endif
}

Expand Down Expand Up @@ -1158,6 +1162,8 @@ public enum Device {
return allTVs
#elseif os(watchOS)
return allWatches
#else
return []
#endif
}

Expand Down Expand Up @@ -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
}

Expand All @@ -1235,8 +1243,10 @@ public enum Device {
} else {
return UIDevice.current.systemName
}
#else
#elseif canImport(UIKit)
return UIDevice.current.systemName
#else
return nil
#endif
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -1385,6 +1401,8 @@ public enum Device {
}
#elseif os(tvOS)
return nil
#else
return nil
#endif
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -2298,6 +2326,8 @@ extension Device {
case .simulator(let model): return model.cpu
case .unknown: return .unknown
}
#else
return .unknown
#endif
}
}
Expand Down Expand Up @@ -2347,6 +2377,8 @@ extension Device.CPU: CustomStringConvertible {
case .s9: return "S9"
case .unknown: return "unknown"
}
#else
return "unknown"
#endif
}
}
42 changes: 37 additions & 5 deletions Source/Device.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -482,6 +484,8 @@ public enum Device {
}
#elseif os(tvOS)
return (width: -1, height: -1)
#else
return (width: -1, height: -1)
#endif
}

Expand Down Expand Up @@ -761,6 +765,8 @@ public enum Device {
return allTVs
#elseif os(watchOS)
return allWatches
#else
return []
#endif
}

Expand Down Expand Up @@ -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
}

Expand All @@ -838,8 +846,10 @@ public enum Device {
} else {
return UIDevice.current.systemName
}
#else
#elseif canImport(UIKit)
return UIDevice.current.systemName
#else
return nil
#endif
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -893,6 +909,8 @@ public enum Device {
}
#elseif os(tvOS)
return nil
#else
return nil
#endif
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -1468,6 +1496,8 @@ extension Device {
case .simulator(let model): return model.cpu
case .unknown: return .unknown
}
#else
return .unknown
#endif
}
}
Expand All @@ -1490,6 +1520,8 @@ extension Device.CPU: CustomStringConvertible {
% end
case .unknown: return "unknown"
}
#else
return "unknown"
#endif
}
}
13 changes: 13 additions & 0 deletions Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down
Loading