Skip to content

Commit b795cd8

Browse files
committed
Add '#if canImport(SwiftUI)'
1 parent aaefc0e commit b795cd8

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Examples/Sources/MacroExamples/Interface/AccessorMacros.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if canImport(SwiftUI)
14+
1315
import SwiftUI
1416

1517
// MARK: - EnvironmentValue Accessor
@@ -18,3 +20,5 @@ import SwiftUI
1820
@attached(accessor)
1921
public macro EnvironmentValue(for key: any EnvironmentKey.Type) =
2022
#externalMacro(module: "MacroExamplesImplementation", type: "EnvironmentValueMacro")
23+
24+
#endif

Examples/Sources/MacroExamples/Playground/AccessorMacrosPlayground.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// MARK: - EnvironmentValue Accessor
1414

1515
import MacroExamplesInterface
16+
17+
#if canImport(SwiftUI)
18+
1619
import SwiftUI
1720

1821
private struct MyEnvironmentKey: EnvironmentKey {
@@ -30,3 +33,5 @@ func runEnvironmentValueAccessorMacroPlayground() {
3033
environmentValues.myCustomValue = "New value"
3134
print("New myCustomValue: \(environmentValues.myCustomValue)")
3235
}
36+
37+
#endif

Examples/Sources/MacroExamples/Playground/main.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ runPeerMacrosPlayground()
5050

5151
// MARK: - Accessor Macros
5252

53+
#if canImport(SwiftUI)
54+
5355
runEnvironmentValueAccessorMacroPlayground()
56+
57+
#endif

0 commit comments

Comments
 (0)