我正在為我的 macOS 應用程式使用 SwiftUI,并且在嘗試根據用戶是否購買了升級來更改檔案選單時遇到了麻煩。
我有這個:
.commands {
CommandGroup(after: .newItem) {
ExamplesMenu(name: "Open Example")
}
etc.
}
如果用戶沒有購買升級,我想禁用“新建”命令,這樣就可以了:
if didPurchase {
CommandGroup(after: .newItem) {
ExamplesMenu(name: "Open Example")
}
} else {
CommandGroup(replacing: .newItem) {
ExamplesMenu(name: "Open Example")
}
}
但是,這會產生錯誤:
Closure containing control flow statement cannot be used with result builder 'CommandsBuilder'
有沒有辦法在不放棄 SwiftUI 的情況下實作這一目標?
uj5u.com熱心網友回復:
你可以試試這個:
.commands {
didPurchase
? CommandGroup(after: .newItem) { ExamplesMenu(name: "Open Example") }
: CommandGroup(replacing: .newItem) { ExamplesMenu(name: "Open Example") }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/362577.html
上一篇:如何在mac上安裝Vue?
下一篇:如何在bash中獲取標準輸出?
