I am trying to extract just the id's from the Properties Array to form a separate array. So far I have come up with this:
struct Interactions: View {
@State var A: [Properties] = [
.init(id: 5, name: "Five"),
.init(id: 8, name: "Eight"),
.init(id: 2, name: "Two")
]
var body: some View {
List(loadIdArray(), id: \.self) { i in
Text("\(i)")
}
}
func loadIdArray() -> [Int] {
let ids: [Int] = [1, 2]
for i in 0 ..< self.A.count {
let ids = [self.A[i].id, self.A[i + 1].id]
return ids
}
return ids
}
}
The problem is that I would have to manually type each [self.A[I + ...].id] which defeats the purpose of the function.
The answer I want is for loadIdArray() = [5, 8, 2] and for it to do this automatically depending on how many items are in the 'A' array.