Reputation:
I have different keys and items to add to a dictionary:
City + Berlin
City + London
City + New York City
Movie + Horror
Movie + Science-Fiction
Movie + Thriller
Food + Burger
Food + Vegetables
Food + Ice Cream
Sports + Baseball
Sports + Soccer
Sports + Tennis
Technology + Apple
I want the matching keys to be one key and the values as an array matching that one key like this:
City: [Berlin, London, New York]
Movie: [Horror, Science-Fiction, Thriller]
etc.
Every pair (one key + matching values) should be together in one UICollectionViewCell.
I have searched for creating and accessing a dictionary, but I just cannot find the right solution for this.
Thank you!
Upvotes: 0
Views: 41
Reputation: 53161
Assuming each of the items you show are strings, you need to declare a dictionary of type [String: [String]]
(key is type String
and value is an array of String
)
let dictionary = [
"City": ["Berlin", "London", "New York"],
"Movie": ["Horror", "Science-Fiction", "Thriller"],
// ...etc.
]
Upvotes: 2