-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
187 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"originHash" : "dd25aeaaf4e3c7cfdf3331d9ffc34f44dbd75c0585bfcf9d8f0bb0c620d577f1", | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-syntax", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-syntax.git", | ||
"state" : { | ||
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d", | ||
"version" : "509.1.1" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
/// A macro that produces both a value and a string containing the | ||
/// source code that generated the value. For example, | ||
/// This macro allows you to easily generate the `==` operator for object types, reducing boilerplate code. | ||
/// | ||
/// #stringify(x + y) | ||
/// Here is how you can use the `Equatable` macro: | ||
/// | ||
/// produces a tuple `(x + y, "x + y")`. | ||
@attached(extension, conformances: Equatable) | ||
public macro equatable() = #externalMacro(module: "MacroExamplesImplementation", type: "EquatableExtensionMacro") | ||
/// ```swift | ||
/// @Equatable | ||
/// final class MyClass { | ||
/// var x: Int | ||
/// var y: Int | ||
/// } | ||
/// | ||
/// let a = MyClass(x: 1, y: 2) | ||
/// let b = MyClass(x: 1, y: 2) | ||
/// | ||
/// // Now you can use the == operator | ||
/// assert(a == b) | ||
/// ``` | ||
@attached(extension, conformances: Equatable, names: named(==)) | ||
public macro Equatable() = #externalMacro(module: "EquatableMacros", type: "EquatableExtensionMacro") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import Equatable | ||
|
||
let a = 17 | ||
let b = 25 | ||
@Equatable | ||
final class Planet { | ||
let name: String | ||
|
||
init(name: String) { | ||
self.name = name | ||
} | ||
} | ||
|
||
let (result, code) = #stringify(a + b) | ||
let planet1 = Planet(name: "Mars") | ||
let planet2 = Planet(name: "Venus") | ||
|
||
print("The value \(result) was produced by the code \"\(code)\"") | ||
print("The value \(planet1 == planet2)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters