This works great, so thanks for that and I have marked the answer as solution.
However, I have managed to find a way where it doesn't work quite as I expected.
I have used the same way of doing it on another page where I'm checking to see if the result set is empty and if its not, then set a @State var to true.
I put the check in after the fetch request, but it always reports that the results are empty.
if cdlodges.isEmpty == false {
//not empty so set fav to true
favourite = true
}
else {
//not a favourite so set to false
favourite = false
}
If I add a button to the page with the same code in, it works fine.
I'm assuming that where its done after the FetchRequest, the query hasn't had chance to fill the resultset in time.
Is there a way to get the check to run on completion of the FetchRequest?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: