I have gone through from multiple tutorials that flatMap/compactMap
is used to flatten
an array of array but in my case it's not working or I am not understanding it properly.
let myArray = [["Raja","Kumar", nil,"Waqas"],["UAE","SINGAPORE","dUBAI","HONGKONG"]]
let final = myArray.compactMap{ $0 }
print("Result:\(final)")
OutPut:
Result:[[Optional("Raja"), Optional("Kumar"), nil, Optional("Waqas")], [Optional("UAE"), Optional("SINGAPORE"), Optional("dUBAI"), Optional("HONGKONG")]]
I tried removing nil from the above array but still it's not flattening my array.
Any help would be much appreciated.