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!
.constantcan only be used to create boolean Bindings. But that's not true. You can pass ANY Swift data type into method.constant()because it takes in a generic parameter. With that said, please see and accept my answer.