I went over that, but If I choose .hourAndMinute it will show even the am/pm. Also I need the values in minutes and seconds, not time and a counter starting from 0 on the hours section, not a spiral of numbers
Post
Replies
Boosts
Views
Activity
The error says:Error saving: The operation couldn’t be completed. (Foundation._GenericObjCError error 0.), [:]Not very helpful :/
The init was a noob way of doing it, an example of what I was trying to do. Your answer above is excactly what I was trying to accomplish but I couldn't since every time I called the funcion in the view it would complain since there cannot be some structs or func in the view by itself. Many thanks!!
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.
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?
True, agreed. Could you point me out to the simplest example possible for when the UI might change automatically without the user interaccion based on some logic happening in the future?
Actually that might be exactly what I need, do you have such code? Also I might quit the app, is that 5 seconds going to count while the app is in the background?
Yep, that is the current specs of the app. The user minimizes the app, locks the screen, when comes back, the button shoud change according to some variable (for example, the counter you mentioned).What would be the best approach for this?
Actually that works very well. For this app that will do the trick, the next one I might have to dig deeper, but that there solves the current problem. Many thanks 🙂
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)
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...
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?
Yeah core data is not too well integrated with swiftui, I'll find a workaround with more old fashion like you said. thanks
Thanks, the create Data works beautifuly, just as expected, with so much going around.The readData() on the other hand gives me an error on your 2nd code, line 3. It says:Value of type 'NSFetchRequest<ProgrammingLanguage>' has no member 'sortDescriptor'what's happening?
Hi, I really appreciate the gesture. I went to github and that project is in Scala, not SwiftUI, did I go to the right one?