我正在使用Xcode 12中的新MultiPlatform SwiftUI Document模板,但我不知道如何从菜单项中访问当前的FileDocument。
我的应用代码看起来像这样(直接从模板复制)。
@main
struct MyApp: App {
var body: some Scene {
DocumentGroup(newDocument: MyDocument()) { file in
ContentView(document: file.$document)
}
.commands {
CommandMenu("Utilities") {
Button(action: {
// How to get access to the current FileDocument ?
}) {
Text("Test")
}
}
}
}
}