My app allows users to store data for individual items. There are many properties for an item, but here is a simplified version:
struct Item: Identifiable, Codable {
let name: String
let id = UUID().uuidString
}
I need to give users the option to assign each item to a container (which users can also create and manage).
struct Container {
let name: String
}
So an item can be in zero or one containers and I will store arrays of all items and all containers. I need to be able to filter the displayed data based on individual containers.
My issue is how best to represent the relationship between the items and containers, and how I should keep track of this state.
I am unsure which of these options is best (or if an alternative might be better):
- Each item has a string property called
container
- Each
container
struct has an array of items that it contains
- All data stored as an array property in a single struct with a separate array of containers and the ID of items they contain
- Some other way
I will be persisting the data locally and in iCloud using CloudKit.
Any advice on a good way to structure this would be appreciated.