Post

Replies

Boosts

Views

Activity

Programmatically create MenuBarExtra elements
I have the following conceptual code: import SwiftUI @main struct SwiftBarApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } ForEach(appDelegate.menuItems, id:\.self) { menuItemSet in MenuBarExtra("Title") { MenuBarView(menuItemSet: menuItemSet) } } } I am attempting to create multiple menu bar items using MenuBarExtra, based upon the content of appDelegate.menuItems. Clearly, my approach does not work as ForEach is supported on Views and not Scenes. Is there an alternate approach that would allow me to have a variable number of menu bar icons?
4
0
686
Aug ’23