This file contains hidden or 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
import Foundation | |
protocol KeyPathListable { | |
var allKeyPaths: [String: PartialKeyPath<Self>] { get } | |
var keyPathsList: [PartialKeyPath<Self>] { get } | |
} | |
extension KeyPathListable { | |
private subscript(checkedMirrorDescendant key: String) -> Any { | |
Mirror(reflecting: self).descendant(key)! |
This file contains hidden or 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
//////////////////////////////////// | |
// Main bundle finding logic | |
import Foundation | |
public protocol BundleFinder: AnyObject { | |
static var packageName: String { get } | |
static var moduleName: String { get } | |
static var packageModule: Bundle { get } | |
} |
Swift Macro
分为两部分,一部分为宏的具体实现(编译器插件),一部分为Macro Lib
用于导出宏定义以及所需要的附属代码,这里说的不使用SPM
指的是编译器插件这部分- 仔细观察
Xcode
使用SPM
集成Macro
时,在编译命令中通过-load-plugin-executable
参数指定了对应宏实现的插件可执行文件路径 - 同时在
swift
源码中也找到了相关参数TypeCheckMacros.cpp TypeCheckMacros.cpp - 从
swift
源码中可得知,宏实现插件即可以是动态库(dylib)也可以是可执行文件 - 系统内置的宏实现是通过
-plugin-path <dylib path>
加载 - 内置的宏实现动态库在
Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/Lib/swift/host/plugins
- 编写宏实现代码,这一步可以通过
SPM
也可以直接通过Xcode
创建命令行程序项目,完成宏实现代码编写
OlderNewer