I have a bunch or arrays in a data struct that I am combining into one array and deleting any duplicates. Is it possible to move an item to the top of the array so it is first in the list? I want All to appear at the top of the list but it is currently sitting in the second position because of Agriculture.
Here are some of the arrays in the data struct:
let productData: [ProductModel] = [
ProductModel(application: ["All", "Clean Chemistry", "Food", "Agriculture", "Polymers"]),
ProductModel(application: ["All", "Food", "Agriculture", "Gin", "Polymers"]),
ProductModel(application: ["All", "Metals", "Polymers"]),
]
Here is where I am organising the array and presenting it in a HStack:
struct ProductList: View {
var applicationsArray = Array(Set(productData.flatMap(\.application))).sorted()
var body: some View {
ScrollView(.horizontal){
HStack{
ForEach(applicationsArray, id: \.self) { item in
Button(action: {
// SELECT ITEM
}) {
VStack(alignment: .center){
Image(item)
Text(item)
}
}
}
}
}
}
}