Error:Ambiguous use of 'FamilyMembers'in line 25
Add a Comment
You may be new to the forum, so you don't know yet the good practices.
For your question: do we need to count ourselves ti find which is line 25 ?
I checked in Xcode, it is this one:
ForEach(FamilyMembers, id: \.name){ (FamilyMember) in
Reason is that you use the same name FamilyMembers for the struct and for the instance.
So change the code as follows:
struct List_View: View {
struct FamilyMembers: Hashable {
let name: String
let thing: String
}
@State private var familyMembers = [ // <<-- lowerCase
FamilyMembers(name: "Dad", thing: "It is my Dad, he set's many rules that is annoying." ),
FamilyMembers(name: "Mum", thing: "It is my Mum, I love her,she always kiss me." ),
FamilyMembers(name: "Brother", thing: "It is my little brother, he is cute but naughty." ),
FamilyMembers(name: "grandpa", thing: "It is my grandfather, He often asks IQ qestions for me to answer." ),
FamilyMembers(name: "grandma", thing: "It is my grandmother, she is fun but serious." )
]
var body: some View {
NavigationView {
List{
ForEach(familyMembers, id: \.name){ familyMember in // <<-- lowerCase
NavigationLink(destination:
VStack {
Text(familyMember.thing) // <<-- lowerCase and $familyMember, not $familyMembers
}
){
HStack{
Text(familyMember.name) // <<-- lowerCase and $familyMember, not $familyMembers
}
}
}
}
}
.navigationTitle("My Family Members")
}
}
And don't forget to close the thread on the correct answer if that works now. Otherwise, explain what the remaining problem is.