The title might be confusing but here is an example data to give a clear understanding
struct City {
var name: String?
var businesses: [Business]?
}
So if i have a city array, i wish to merge the businesses array based on the city name since the city may have duplicates e.g.
[
{
name: "CIty 1"
businesses: [
{ name: "Business 1" },
{ name: "Business 2" },
]
},
{
name: "CIty 2"
businesses: [
{ name: "Business 1" },
{ name: "Business 2" },
]
}
{
name: "CIty 1"
businesses: [
{ name: "Business 3" },
{ name: "Business 4" },
]
}
]
In the data example above, there are 2 entries of City1. i am looking for a way to not have to use a dictionary, if it is possible to use the existing array and output it such that there is only 1 entry of City but will contain 4 entries of business.
Thoughts?