Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Day 27: Project 4: BetterRest (Part Two)

Follow along at https://www.hackingwithswift.com/100/swiftui/27.

📒 Field Notes

This day covers Part Two of Project 4: BetterRest in the 100 Days of SwiftUI Challenge. (Project 4 files can be found in the directory for Part One.)

It focuses on several specific topics:

  • Building a basic layout
  • Connecting SwiftUI to Core ML
  • Cleaning up the user interface

Building a basic layout

Rendering the DatePickers label directly can be a bit visually awkward. I wrote up an article recently on a solution I tend to prefer instead, which includes rendering the label as a separate Text element above the picker.

VStack {
    Text("When do you want to wake up?")
        .font(.headline)

    DatePicker("Please enter a time", selection: $wakeUp, displayedComponents: .hourAndMinute)
        .labelsHidden()

    // more to come
}

Connecting SwiftUI to Core ML

Dragging an output CreateML model into our Xcode project will generate a Swift class with the same name (in camel-case).

Through this model, we're given a prediction function that can take whatever features it's parameterized on and generate a value for the result that it's trained to predict. That's really just scratching the surface, but it's perfect for our app's coffee cut-off time prediction.

Cleaning up the user interface

Lookin' alright...