Skip to content

Instantly share code, notes, and snippets.

@Thonyvb
Created March 18, 2022 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thonyvb/69dff923fc54ed123404b16e1b7e4600 to your computer and use it in GitHub Desktop.
Save Thonyvb/69dff923fc54ed123404b16e1b7e4600 to your computer and use it in GitHub Desktop.
SwiftUI Property Wrapper Binding
struct ProductView: View {
@State private var isFavorite: Bool = false
var body: some View {
// ...
FavButton(isFavorite: $isFavorite) // Pass a binding.
}
}
struct FavButton: View {
@Binding var isFavorite: Bool
var body: some View {
Button(action: {
isFavorite.toggle()
}, label: {
Image(isFavorite ? "Filled_Heart" : "Heart")
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment