I cannot seem to figure out how to initialize a @Binding that is of type Array:
struct RecipeItemDetailView: View {
@Binding var recipeDetails: [StoredRecipeModel]
var body: some View {
NavigationView {
VStack {
Text(recipeDetails[1].name)
}
}
}
struct RecipeItemDetailView_Previews: PreviewProvider {
static var previews: some View {
RecipeItemDetailView(recipeDetails: <#Binding<[StoredRecipeModel]>#>)
}
In the above, you will see that in the PreviewProvider after "recipeDetails: " it is asking that I initialize recipeDetails. I put the sample code in that is is asking for. I am able to initialize less complex bindings (e.g. .constant(false) ) but that does not work in this case.
Any thoughts?
Hopefully I am using the correct terms here, as I am quite new to programming!
Update: I was able to figure it out. The following code appears to work:
struct RecipeItemDetailView_Previews: PreviewProvider {
static var previews: some View {
RecipeItemDetailView(recipeDetails: .constant([StoredRecipeModel].init()))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With