The following class has some variables inside of it.
class Person {
var age: Int = 4
var items = [String]()
}
var allPeople = [Person]()
var allItems = [String]()
Assuming we created initializers for the class and allPeople has n elements in it, I would like to merge all items for each object into a new array
The problem comes when I try to access each index of allPeople, and from there, get the items variable and append it to allItems. But I need to specify a number that changes according to the total number of elements. My initial attempt was to use a for loop. Also using allPeople[allPeople.count - n], something similar to this.
let allItems = allPeople.flatMap { $0.items }?flatmap. I was usingmapwhich was incorrect...