How to change text in SwiftUI conditional button to systemImage?

This is my modifier for a view, I want to display the SF symbols by using systemImage: "heart.fill" instead of "-" and systemImage: "heart" instead of "+" but XCode myseriously fails to build without any error.

        .toolbar {
            ToolbarItem(placement: .navigationBarTrailing) {
                Button(favorites.contains(item) ? "-" : "+") {
                    if favorites.contains(item) {
                        favorites.remove(item)
                    } else {
                        favorites.add(item)
                    }
                }
            }
        }

How do I print the SF symbol instead of a String? Thanks in advance.

Sorry, what's your question here?

You say you want to use systemImage, but that Xcode fails to build and doesn't display any error. The code you've provided should compile correctly, and you don't mention any SF symbols in it. Can you post the correct code that might enable us to answer your query?

You're calling a Button initializer that expects a String as its first parameter. Instead, you need to use a different initializer to provide the button's content. To actually change the symbol being used, you can use the .symbolVariant modifier to switch between a variant of .fill and a variant of .none.

        .toolbar {
            ToolbarItem(placement: .navigationBarTrailing) {
                Button {
                    if favorites.contains(item) {
                        favorites.remove(item)
                    } else {
                        favorites.add(item)
                    }
                } label: {
                    Image(systemImage: "heart")
                        .symbolVariant(favorites.contains(item) ? .fill : .none)
                }
            }
        }
How to change text in SwiftUI conditional button to systemImage?
 
 
Q