Post

Replies

Boosts

Views

Activity

Reply to Type '()' cannot conform to 'View error
I see what the problem was... I wasn't notifying the view of new data coming from the other class (aka: ObservableObject). But how do I make the data from the loop published?I tested a simple example:@Published var counter: Int = 0 func ResetDay() { print("\(counter)") counter += 1 }and that works, but if I try to make coredata published (the wrong way I see...), it gives an error:@FetchRequest( entity: Settings.entity(), sortDescriptors: [] ) @Published var settingsData: FetchedResultsSo since the other view isn't aware of coredata settingsData how can I make it aware?
May ’20
Reply to Type '()' cannot conform to 'View error
Which part? So far this operation only has 3 components, I have't included any logic yet. I have:1- A brand new swift class with the simple funcion calling 2- coredata and 3- the view from which I'm calling the funcion that has nothing than a simple buttonI just tested the same thing within the Struct of the view that I'm using to call the funcion and it works, so the issue is when calling it from another class... interesting...
May ’20
Reply to Type '()' cannot conform to 'View error
I tried:func ResetDay() { for index in 0...self.mealData.count-1 { print("\(index)") } }and calling it in another view:Button(action: { MyClass().ResetDay() }) { Text("Reset Day") .foregroundColor(.red) }But it gives me an error: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
May ’20
Reply to View not refreshed when .onAppear runs SwiftUI
Ok, I thought of a better way of explaining it. How can I make the UI update itself without the user having to interact with it?For example: I have the user that clicks the button, Eat, and that records the current time and calculates future time when that is due. Since I can't put a function in the view (which is very annoying), I thought to check for time on .onAppear(), and if the next time the user is suppoused to eat is less than the current time, then change the value stored in DB to "overdue", if that value is overdue, display the button with another look.So what I need is the UI to change when that value becomes overdue without me having to click a button, if it's still not clear let me know so I can think on a simpler way of explaining it.It's imposible that for the UI to change the user has to interact with it everytime, is it?
May ’20
Reply to View not refreshed when .onAppear runs SwiftUI
No, what I'm expecting is when the value changes, when future date becomes less than actual date, the UI change automatically without me having to go to second view and come back. Am I doing that the right way?In my code it's for a button to change when it's passed due. The thing is that the user could quit the app or minimize it.
May ’20