I have two structs and a class. when I call on the class in which I have created instances for one of the structs. I want to append them to an array in the other struct when the class is called. Is there a way to do this?
struct People {
let name: String
let age: Int
}
struct Group {
var groupOfPeople: [People] = []
}
class example {
var group1 = Group()
let person1 = People(name: "Jay", age: 44)
let person2 = People(name: "Sarah", age: 35)
let person3 = People(name: "Eric", age: 21)
let person4 = People(name: "Tara", age: 10)
group.groupOfPeople.append(contentsOf: [person1, person2, person3, person4])
}
This won't work, is there another way to do it?