Inc. (since May, 2021) • Occupation ◦ Software Engineer, Android (and iOS at some of my previous companies) • Accounts ◦ Twitter: @tkhs0604 ◦ GitHub: @tkhs0604 ◦ Bluesky: @kenken.bsky.social • Other ◦ DroidKaigi community staff
You can use it after Xcode 15.0 beta • A tool for generating boilerplate codes repetitively written by hand • #Preview, @Observable etc. are created with Swift macros Cited from: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/macros/
code at compile time ◦ Input code to a macro and output code of macro expansion are validated syntactically ◦ Values passed to a macro and in the code generated by a macro are type-checked ◦ If the implementation of a macro has any error, Swift compiler treats it as a compilation error Cited from: https://developer.apple.com/videos/play/wwdc2023/10167/?time=291
launch and the name of a type inside the plug-in • When Swift expands the following macro, #stringify(_:) will launch a plug-in called "MyLibMacros" and ask a type called "StringifyMacro" to expand it Cited from: https://developer.apple.com/videos/play/wwdc2023/10167/?time=1102
abstract syntactic structure of a source code • SwiftSyntax is a library that helps us parse, inspect, manipulate, and generate Swift source code ◦ https://github.com/apple/swift-syntax Cited from: https://developer.apple.com/videos/play/wwdc2023/10167/?time=1288
codes • Inputs and outputs are syntax-checked and type-checked at compile time • Some useful macros, like #preview and @Observable have already been introduced • SwiftSyntax is an essential tool for implementing macros ◦ Quite difficult to understand… 😇 • So… let’s try to create macros by yourself and share knowledges!