You can use the map
method, which transform an array of a certain type to an array of another type – in your case, from array of Employee
to array of Int
:
var array = [Employee]()
array.append(Employee(id: 4, firstName: "", lastName: ""))
array.append(Employee(id: 2, firstName: "", lastName: ""))
let ids = array.map { $0.id }