One of my tables has 100 rows. Can't be helped, just the nature of the app. When I fetch the data, I need to assign the values in order to fields on the screen. I've created an outlet collection to make this easy and would like to do this in a for loop to minimize the code.
I'm having trouble understanding the nature of the fetch to make this easy..... I understand I'm fetching into an array of the type of the data.
In my example, just to make it clear, I fetch two sorted rows - the first fetched row [0] brings back .tile_1_1, through .tile_10_10 and has the "correct values". The second fetched row [1] brings back the "given values" for all of these tiles and is also the "current values", hence the assignment made in the for loop.
I need to change the .tile_1_1 to work in the for loop, but can't figure out what type of equivalent "index" for the data I'm trying to find - it's not a 3 dimensional array, but I can't quite wrap my head around this. Can someone point me in the right direction, please? Should I be trying to retrieve this into a dictionary first, or some other retrieval method?
It would be something like (for the first code line):
tileButtons[x].correctValue = Int(truncating: fetchingDataTiles[0].index[x]
My alternative is what I have now and haven't included - a massive, manual retrieval and assignment code segment. It's long ang ugly, and while it works and I have it done, I'd like to eliminate it for several reasons including the opportunity for breakage in the future.
I hope my explanation makes sense - and that the question is a basic one that I probabluy should know the answer to but just don't... the solution is probably a simple one too - I hope!
for x in 0..<tileButtons.count {
// TODO: Fix this for the right fetchedDataTiles data
tileButtons[x].correctValue = Int(truncating: fetchedDataTiles[0].tile_1_1!)
tileButtons[x].givenValue = Int(truncating: fetchedDataTiles[1].tile_1_1!)
tileButtons[x].currentValue = Int(truncating: fetchedDataTiles[1].tile_1_1!)
}
Thanks in advance!