10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- import Foundation
14
-
15
- /// "Stringify" the provided value and produce a tuple that includes both the
16
- /// original value as well as the source code that generated it.
17
- @freestanding ( expression) public macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroExamplesImplementation " , type: " StringifyMacro " )
18
-
19
- /// Macro that produces a warning on "+" operators within the expression, and
20
- /// suggests changing them to "-".
21
- @freestanding ( expression) public macro addBlocker< T> ( _ value: T ) -> T = #externalMacro( module: " MacroExamplesImplementation " , type: " AddBlocker " )
22
-
23
- /// Macro that produces a warning, as a replacement for the built-in
24
- /// #warning("...").
25
- @freestanding ( expression) public macro myWarning( _ message: String ) = #externalMacro( module: " MacroExamplesImplementation " , type: " WarningMacro " )
26
-
27
- public enum FontWeight {
28
- case thin
29
- case normal
30
- case medium
31
- case semiBold
32
- case bold
33
- }
34
-
35
- public protocol ExpressibleByFontLiteral {
36
- init ( fontLiteralName: String , size: Int , weight: FontWeight )
37
- }
38
-
39
- /// Font literal similar to, e.g., #colorLiteral.
40
- @freestanding ( expression) public macro fontLiteral< T> ( name: String , size: Int , weight: FontWeight ) -> T =
41
- #externalMacro( module: " MacroExamplesImplementation " , type: " FontLiteralMacro " )
42
- where T: ExpressibleByFontLiteral
43
-
44
- /// Check if provided string literal is a valid URL and produce a non-optional
45
- /// URL value. Emit error otherwise.
46
- @freestanding ( expression) public macro URL( _ stringLiteral: String ) -> URL = #externalMacro( module: " MacroExamplesImplementation " , type: " URLMacro " )
47
-
48
- /// Apply the specified attribute to each of the stored properties within the
49
- /// type or member to which the macro is attached. The string can be
50
- /// any attribute (without the `@`).
51
- @attached ( memberAttribute)
52
- public macro wrapStoredProperties( _ attributeName: String ) = #externalMacro( module: " MacroExamplesImplementation " , type: " WrapStoredPropertiesMacro " )
13
+ // MARK: - Dictionary Storage
53
14
54
15
/// Wrap up the stored properties of the given type in a dictionary,
55
16
/// turning them into computed properties.
@@ -66,6 +27,8 @@ public macro DictionaryStorage() = #externalMacro(module: "MacroExamplesImplemen
66
27
@attached ( accessor)
67
28
public macro DictionaryStorageProperty( ) = #externalMacro( module: " MacroExamplesImplementation " , type: " DictionaryStoragePropertyMacro " )
68
29
30
+ // MARK: - Observable
31
+
69
32
public protocol Observable { }
70
33
71
34
public protocol Observer < Subject> {
@@ -108,29 +71,7 @@ public macro Observable() = #externalMacro(module: "MacroExamplesImplementation"
108
71
@attached ( accessor)
109
72
public macro ObservableProperty( ) = #externalMacro( module: " MacroExamplesImplementation " , type: " ObservablePropertyMacro " )
110
73
111
- /// Adds a "completionHandler" variant of an async function, which creates a new
112
- /// task , calls thh original async function, and delivers its result to the completion
113
- /// handler.
114
- @attached ( peer, names: overloaded)
115
- public macro AddCompletionHandler( ) =
116
- #externalMacro( module: " MacroExamplesImplementation " , type: " AddCompletionHandlerMacro " )
117
-
118
- @attached ( peer, names: overloaded)
119
- public macro AddAsync( ) =
120
- #externalMacro( module: " MacroExamplesImplementation " , type: " AddAsyncMacro " )
121
-
122
- /// Add computed properties named `is<Case>` for each case element in the enum.
123
- @attached ( member, names: arbitrary)
124
- public macro CaseDetection( ) = #externalMacro( module: " MacroExamplesImplementation " , type: " CaseDetectionMacro " )
125
-
126
- @attached ( member, names: named ( Meta) )
127
- public macro MetaEnum( ) = #externalMacro( module: " MacroExamplesImplementation " , type: " MetaEnumMacro " )
128
-
129
- @attached ( peer)
130
- public macro CodableKey( name: String ) = #externalMacro( module: " MacroExamplesImplementation " , type: " CodableKey " )
131
-
132
- @attached ( member, names: named ( CodingKeys) )
133
- public macro CustomCodable( ) = #externalMacro( module: " MacroExamplesImplementation " , type: " CustomCodable " )
74
+ // MARK: - Option Set
134
75
135
76
/// Create an option set from a struct that contains a nested `Options` enum.
136
77
///
0 commit comments