Im trying to use a textfield to take a string and then when the save button is clicked, it saves that value typed as a double using CoreData. But it keeps giving an error stating that "Value of optional type 'Double?' must be unwrapped to a value of type 'Double'" Any ideas?
- hoursSlept is the variable the textfield is bonded to
- newSleep is the variable for the struct SleepModel (my sleep type)
- Im taking the textfield value and trying to force into a double using Double() with a new variable. But it keeps giving the error.
Button(action: {
var hoursSleptDouble = Double(hoursSlept)
newSleep!.hoursSlept = hoursSleptDouble
if newSleep != nil {
coreDataViewModel.saveRecord(sleepModel: newSleep!) {
print("Success")
}
}
})
{
Capsule()
.foregroundColor(Color.green)
.frame(height: 44)
.overlay(Text("Add Entry").foregroundColor(Color.white).bold())
}.padding()