├── LICENSE └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Artem Novichkov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Awesome Swift Macros 2 | A hand-curated list of Swift macros. Feel free to contribute! 3 | 4 | ## WWDC23 5 | 6 | - [Discover Observation in SwiftUI](https://developer.apple.com/videos/play/wwdc2023/10149) 7 | - [Expand on Swift macros](https://developer.apple.com/videos/play/wwdc2023/10167) 8 | - [Write Swift macros](https://developer.apple.com/videos/play/wwdc2023/10166) 9 | 10 | ## Macros 11 | 12 | - [Swift Macro Examples](https://github.com/DougGregor/swift-macro-examples) 13 | 14 | ```swift 15 | // "Stringify" macro turns the expression into a string. 16 | #stringify(x + y) 17 | 18 | // "AddBlocker" complains about addition operations. We emit a warning 19 | // so it doesn't block compilation. 20 | #addBlocker(x * y + z) 21 | 22 | // "#URL" macro provides compile time checked URL construction. If the URL is 23 | // malformed an error is emitted. Otherwise a non-optional URL is expanded. 24 | #URL("https://swift.org/") 25 | ``` 26 | 27 | - [swift Power Assert](https://github.com/kishikawakatsumi/swift-power-assert) 28 | 29 | ```swift 30 | #powerAssert(max(a, b) == c) 31 | | | | | | 32 | 7 4 7 | 12 33 | false 34 | ``` 35 | 36 | - Preview macro (Xcode 15+) 37 | ```swift 38 | #Preview { 39 | Button("SwiftUI") {} 40 | } 41 | ``` 42 | 43 | - [SFSymbolsMacro](https://github.com/lukepistrol/SFSymbolsMacro) 44 | 45 | ```swift 46 | import SFSymbolsMacro 47 | import SwiftUI 48 | 49 | @SFSymbol 50 | enum Symbols: String { ... } 51 | ``` 52 | 53 | ## Proposals 54 | 55 | * [SE-0382: Expression macros](https://github.com/DougGregor/swift-evolution/blob/se-0382-expression-macros-updates/proposals/0382-expression-macros.md) 56 | * [SE-0389: Attached Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md) 57 | * [SE-0394 Package Manager Support for Custom Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0394-swiftpm-expression-macros.md) 58 | --------------------------------------------------------------------------------