I have updated the code for my Touch Bar as shown below. My app successfully runs on iPhone and iPad however on Mac, it fails to run and produces the errors shown in my screenshot.
Any thoughts on how to fix this would be great.
Many thanks.
import UIKit
#if targetEnvironment(macCatalyst)
extension NSTouchBarItem.Identifier {
static let deleteRecipe = NSTouchBarItem.Identifier("com.example.apple-samplecode.Recipes.deleteRecipe")
static let editRecipe = NSTouchBarItem.Identifier("com.example.apple-samplecode.Recipes.editRecipe")
static let toggleRecipeIsFavorite = NSTouchBarItem.Identifier("com.example.apple-samplecode.Recipes.toggleRecipeIsFavorite")
}
extension ViewController2: NSTouchBarDelegate {
override func makeTouchBar() -> NSTouchBar? {
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.defaultItemIdentifiers = [
.flexibleSpace,
.deleteRecipe,
.flexibleSpace,
.editRecipe,
.toggleRecipeIsFavorite,
.flexibleSpace
]
return touchBar
}
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
let touchBarItem: NSTouchBarItem?
switch identifier {
// case .deleteRecipe:
// guard let image = UIImage(systemName: "trash") else { return nil }
// touchBarItem = NSButtonTouchBarItem(identifier: identifier,
// image: image,
// target: self,
// action: #selector(RecipeDetailViewController.deleteRecipe(_:)))
//
case .editRecipe:
guard let image = UIImage(systemName: "square.and.pencil") else { return nil }
touchBarItem = NSButtonTouchBarItem(identifier: identifier,
image: image,
target: self,
action: #selector(abc(_:)))
// case .toggleRecipeIsFavorite:
// guard let recipe = self.recipe else { return nil }
//
// let name = recipe.isFavorite ? "heart.fill" : "heart"
// guard let image = UIImage(systemName: name) else { return nil }
//
// touchBarItem = NSButtonTouchBarItem(identifier: identifier,
// image: image,
// target: self,
// action: #selector(RecipeDetailViewController.toggleFavorite(_:)))
default:
touchBarItem = nil
}
return touchBarItem
}
}
// Action on 'Photos' tab:
struct abc: View {
var body: some View {
storyboardview2().edgesIgnoringSafeArea(.all) // ViewController2 (Photos page)
}
}
#endif
Topic:
Programming Languages
SubTopic:
Swift
Tags: