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 2 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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.8
//===----------------------------------------------------------------------===//
Zandor300 marked this conversation as resolved.
Show resolved Hide resolved
//
// This source file is part of the DeviceKit open source project
Expand Down
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 @@ -1128,6 +1132,8 @@ public enum Device {
return allTVs
#elseif os(watchOS)
return allWatches
#else
return []
#endif
}

Expand Down Expand Up @@ -1189,8 +1195,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 @@ -1205,8 +1213,10 @@ public enum Device {
} else {
return UIDevice.current.systemName
}
#else
#elseif canImport(UIKit)
return UIDevice.current.systemName
#else
return nil
#endif
}

Expand All @@ -1215,8 +1225,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 @@ -1225,8 +1237,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 @@ -1235,8 +1249,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 @@ -1355,6 +1371,8 @@ public enum Device {
}
#elseif os(tvOS)
return nil
#else
return nil
#endif
}

Expand Down Expand Up @@ -1506,6 +1524,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 @@ -1634,6 +1657,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 @@ -2268,6 +2296,8 @@ extension Device {
case .simulator(let model): return model.cpu
case .unknown: return .unknown
}
#else
return .unknown
#endif
}
}
Expand Down Expand Up @@ -2317,6 +2347,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 @@ -418,6 +418,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 @@ -479,6 +481,8 @@ public enum Device {
}
#elseif os(tvOS)
return (width: -1, height: -1)
#else
return (width: -1, height: -1)
#endif
}

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

Expand Down Expand Up @@ -789,8 +795,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 @@ -805,8 +813,10 @@ public enum Device {
} else {
return UIDevice.current.systemName
}
#else
#elseif canImport(UIKit)
return UIDevice.current.systemName
#else
return nil
#endif
}

Expand All @@ -815,8 +825,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 @@ -825,8 +837,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 @@ -835,8 +849,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 @@ -860,6 +876,8 @@ public enum Device {
}
#elseif os(tvOS)
return nil
#else
return nil
#endif
}

Expand Down Expand Up @@ -915,6 +933,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 @@ -947,6 +970,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 @@ -1435,6 +1463,8 @@ extension Device {
case .simulator(let model): return model.cpu
case .unknown: return .unknown
}
#else
return .unknown
#endif
}
}
Expand All @@ -1457,6 +1487,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