Could someone point me in the right direction on how to solve this issue, please?
I am creating table cells with the values from the structure below. The cells are created and the data is displayed in the cells by the time they were created which works fine.
The issue is some of the cells have the same name and I have an individual id for each cell from the struc Data but I need the user to know which one of the duplicates was created first within the duplicates. Kind of like a sub-number.
For example: 1:apple -1 , 2:pear -1, 3:apple -2
1(position in all the cell) - Apple (name of the cell) - 1 (value based on how many cells are named apple)
The func idName() I created tells us how many occurrences of a name happens but how could I break this down so the data would display like above?
struct Data {
var id: Int
var name: String
var color: String
var time: TimeInterval
var sessionId: Int
var userId: Int
}
func idName () {
let idElement = elements //another variable is used to grab the Array
var counts: [String: Int] = [:]
var idValue: Int
for id in idElement {
counts[id.name] = (counts[id.name] ?? 0) + 1
for (key, value) in counts {
print("\(key) occurs \(value) time(s)")
}
}
}