I recreated the code of the instructor and the prediction model coffee data type Double(coffeeAmount) is asking for Int64 and not a Double. I can't figure why its doing this.
//
// ContentView.swift
// BetterRest
//
// Created by Jonathan Loving on 6/22/23.
//
import CoreML
import SwiftUI
struct ContentView: View
{
@State private var wakeUp = Date.now
@State private var sleepAmount = 8.0
@State private var coffeeAmount = 1
var body: some View
{
NavigationView
{
VStack
{
Text("When do you want to wake up")
.font(.headline)
DatePicker("Please enter a time", selection: $wakeUp, displayedComponents: .hourAndMinute)
.labelsHidden()
Text("Desired amout of sleep")
.font(.headline)
Stepper("\(sleepAmount.formatted()) hours", value: $sleepAmount, in: 4...12, step: 0.25)
Text("Daily coffeee intake")
Stepper(coffeeAmount == 1 ? "1 cup" : "\(coffeeAmount) cups", value: $coffeeAmount, in: 1...20)
}
.navigationTitle("BetterRest")
.toolbar
{
Button("Calculate", action: calculateBedtime)
}
}
}
func calculateBedtime()
{
do
{
let config = MLModelConfiguration()
let model = try SleepCalculator(configuration: config)
let components = Calendar.current.dateComponents([.hour, .minute], from: wakeUp)
let hour = (components.hour ?? 0) * 60 * 60
let minute = (components.minute ?? 0) * 60
let prediction = try model.prediction(wake: Double(hour + minute), estimatedSleep: sleepAmount, coffee: Double(coffeeAmount))
} catch {
//Something went wrong
}
}
}
struct ContentView_Previews: PreviewProvider
{
static var previews: some View
{
ContentView()
}
}
Here is the specifice line of code that is having issues:
let prediction = try model.prediction(wake: Double(hour + minute), estimatedSleep: sleepAmount, coffee: Double(coffeeAmount))