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
935
Aug ’23
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?
Replies
4
Boosts
0
Views
935
Activity
Aug ’23
Offline SwiftUI documentation
Does Apple publish SwiftUI documentation in a format that can be consumed offline (epub, pdf or similar)?
Replies
1
Boosts
0
Views
1.2k
Activity
Aug ’23