I started building an app using catalyst, liking the idea of being able to use one code for all three apple devices. Problem is I can not have a simple dropdown on the catalyst app so I decided to split the app and use swiftui but for Mac and iOS so that I can have more Mac style controls like a dropdown.
I spent all of last weekend figuring out how to get the tool bar working in catalyst and I finally was able to. So when I ported the app to Mac I go the following error in my toolbar func on the toolbar delegate
Use of unresolved identifier 'UIBarButtonItem'
I spent all night trying to figure out how to add this simple button to the toolbar and got nowhere. The segment control works fine but can't add a button. For now I am just using a segment control (since its working) with one button and text only.
so how do I add a button (and use the system icons) to NSToolBar on a Mac swiftui app?
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
if (itemIdentifier == tbi1) {
let tbi = NSToolbarItemGroup(itemIdentifier: itemIdentifier, titles: ["Accounts","Budgets"], selectionMode: .selectOne, labels: ["One","Two"], target: self, action: #selector(tbi1_click))
tbi.selectedIndex = 0
return tbi
}
else if (itemIdentifier == tbi2) {
let bbi1 = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(tbi2_click))
let tbi = NSToolbarItem(itemIdentifier: itemIdentifier, barButtonItem: bbi1)
return tbi
}
return nil
}