100 Days of SwiftUI Day 26 ML

100 Days of SwiftUI – Day 26 – BetterRest

It’s day 26 of the 100 Days of SwiftUI! Yesterday, we finished our very own brain training game. Today, we’re learning about the Stepper, using dates and even machine learning! This all is an intro to our fourth project, which is called BetterRest. This app will be designed to help coffee drinkers help a good night sleep. This ought to be very interesting, but unfortunately due to time constraints, today’s recap will be on the short side. Nevertheless, let’s dive in right away!

Entering numbers with Stepper in SwiftUI

The Stepper is used to allow the user to select a precise number in SwiftUI. It adds a plus (+) and minus (-) button with steps that’ve chosen in our code. For example, you could increment or decrement by 1, 0.5, etc.

Stepper("\(sleepAmount.formatted()) hours", value: $sleepAmount, in: 4...12, step: 0.25)

Using dates in SwiftUI

SwiftUI features a DatePicker that allows users to select a date. It can be modified in various ways, for example to only pick a future date or pick a date and time.

DatePicker("Please enter a date", selection: $date, in: Date.now..., displayedComponents: .date)

 Text(Date.now, format: .dateTime.hour().minute().day().month().year())
            Text(Date.now.formatted(date: .long, time: .omitted))

Working with dates is quite tough. We’ve only displayed them now, but there’s a lot more to be done to further implement them in our programs. Paul has written an extensive article on them and we’ll be implementing them in our project as well, to ensure it all sinks in!

Machine Learning introduction with Create ML

Apple has a few very powerful tools for developers. One of them is their machine learning framework: Core ML. This has been introduced a few years ago and has been further built upon since. Today we’ve looked at Create ML, a piece of software that works with Xcode that allows us to train a model using various machine learning algorithms.

Since we haven’t implemented our model in code yet, I will refer to Paul’s article on Create ML for now. Hopefully we’ll have an implementation tomorrow!

That’s it for day 26! Like I said at the beginning, it was going to be a bit short. However, since we’re actually implementing our machine learning model tomorrow, that should make for some very interesting code examples. Time to recharge!

Darryl

Hi! My name is Darryl and this is my personal blog where I write about my journey as I learn programming! You'll also find articles about other things that interest me including games, tech and anime.

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

100 Days of SwiftUI – Day 62

100 Days of SwiftUI – Day 46

100 Days of SwiftUI – Day 57

100 Days of SwiftUI – Day 73