I have a date selector in a view and, once the user enters a date and saves I display a new view with a toggle. Ideally, once the users flips the toggle I'd like to be able to set a reminder using the date field already entered. I have created an ObservableObject
import SwiftUI
import Combine
class UpdateVM: ObservableObject{
@Published var reminderDate = Date() {didSet {
print("set")
}
which I declare in the View as:
@ObservedObject var updateVM = UpdateVM()
if(self.isToggle){
updateVM.reminderDate = flossTheCat.reminderDate!
}
I get an error "Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols"
This works fine in the action area of a button press but I don't see if it's possible to react to a toggle flip - is the toggle just designed to reflect UI changes and should I implement a button instead ? Definitely having a hard time adjusting to the SwiftUI paradigm even if it makes sense overall
Thanks !
per the request - here is where it does work as I hoped it would (via a button)
trailing: Button(action: {
do {
let flossingReminders = FlossingPets.init(context: self.context)
self.flossingVM.reminderDate = self.flossingDate
if self.context.hasChanges {
try self.context.save()
}
}catch {
print(error)
}