I have Array A of objects of type struct
struct Caste {
var arr = [1,2]
}
let siri = [Caste(), Caste(), Caste()]
Now I want a single array in which all elements of each objects array consist as shown below:
let re1 = siri.compactMap { $0.arr }
print("COMPACT: \(re1)")
let re2 = siri.flatMap { $0.arr }
print("FLAT: \(re2)")
Result:
COMPACT: [[1, 2], [1, 2], [1, 2]]
FLAT: [1, 2, 1, 2, 1, 2]
As flatMap is deprecated in Swift 4.1 I tried with compactMap but it is giving array of array not a single array.
How can I achieve via compactMap as I'm getting via flatMap.