I'm having similar trouble, but unfortunately iterating on the indices and passing an array item with subscript won't work for me. My ForEach statement iterates on the struct's name field and simultaneously sorts the array:
ForEach(store.cocktails.sorted {$0.cocktailName < $1.cocktailName }) { ******** in
CocktailCell(********: $********)
}
I don't want to give up the automatic sort, hence, I cannot access the index each time through in order to send a single array item. I do, however, have to pass a binding for the item because at each level below I either want to read the values in the struct or write to them.
The object "store" is instantiated with @StateObject at the parent level, and passed in as an ObservedObject at this view level.
Any ideas?
Post
Replies
Boosts
Views
Activity
Jeez, that didn't post too well...replace the ******* in each case with the word c*ocktail. Ridiculous level of "disallow listing" words.
Any resolution to this issue?
I decode a large data set from a JSON file upon first run of my iOS app. Two simulator devices running on the same iCloud account credentials both "upload" their data set to the cloud although the sets are in all ways identical. A restart of each app shows double entries. Subsequently added data items are synced but not duplicated. Items have a UUID id which is identical between devices. Puzzling how to deliver the app with the desired large data set intact without causing duplicate entries. Is the toggle-a-boolean work-around the only way?
Never mind...I read Consuming Relevant Store Changes in Apple docs and downloaded the sample project Synchronizing a Local Store to the Cloud from 2019. The needed deduplication code is explained and shown in the former and executed in the latter. Beware: there is a code error in the sample project. You want to register for remote change notifications fired by the container.persistentStoreCoordinator, not the container itself.
I found that appending an .id modifier to the detail column resolved the problem for me:
} detail: {
if let selectedCocktail {
CocktailDetailView(pCocktail: selectedCocktail)
.navigationTitle("(selectedCocktail.favorite ? "(profile.userData.favoriteCocktailsIcon.rawValue)" : "") (selectedCocktail.cocktailName ?? "")")
.id(selectedCocktail.id) //workaround
}
I’m considering adding photo attachments to public db storage in my app. I’d held off in light of the free limits a couple of years ago but thought I’d revisit the topic. Apple is doing us no favor by making the pricing info opaque. Has anyone found a resource for this?