I have multiple arrays in a data model. I would like to take an array from each of the data models and concatenate them, then delete the duplicate strings in the array. Is this possible? I'm sure I can work out how to delete the duplicates after but I am struggling to concatenate them first.
My data model (I am trying to concatenate the application array) :
let productData: [ProductModel] = [
ProductModel(
title: "option1",
application: ["Food","Agriculture","Gin","Metals","Poylmers"]
),
ProductModel(
title: "option2",
application: ["Food","Agriculture","Gin", "Polymers"]
),
ProductModel(
title: "option3",
application: ["Food","Metals","Poylmers"]
),
ProductModel(
title: "option4",
application: ["Gin","Metals","Poylmers"]
),
]
Here is where I am trying to append the array but I all I seem to be doing is adding an empty string to each of the arrays:
let applicationItems = products.filter { product in
let list = product.application
var collectedList = [""]
for item in list {
collectedList.append(contentsOf: list)
return true
}
return false
}