This is my custom data struct:
struct Absence {
var type: String
var date: TimeInterval
}
I have an array of this data struct like this:
var absences: [Absence]
I would like a function to return all the types of an absence. I have written this:
func types() -> [String] {
var types = [String]()
for absence in self.absences {
if !types.contains(absence.type) {
types.append(absence.type)
}
}
return types
}
I was wondering if there was a better way of iterating through using either map, compactMap or flatMap. I am new to mapping arrays. Any help much appreciated.