UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Day 27 Proj.4 part 2 - Building a basic layout

Forums > 100 Days of SwiftUI

I was doing the project part 2 and typed as following:

//
//  ContentView.swift
//  BatterRest
//
//  Created by Bo-Shiung Huang on 2020/7/23.
//  Copyright © 2020 com.Bo-Shiung Huang. All rights reserved.
//

import SwiftUI

struct ContentView: View {

    @State private var sleepAmount = 8.0
    @State private var coffeeAmount = 1
    @State private var wakeUp = Date()

    var body: some View {
        NavigationView {
            VStack {
                Text("When do you want to wake up?")
                    font(.headline)

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

                Text("Desire amount of sleep")
                    .font(.headline)

                Stepper(value: $sleepAmount, in:2...14, step: 0.25) {
                    Text("\(sleepAmount, specifier: "%g") hours")
                }
                Text("Daily coffee intake")
                        .font(.headline)

                Stepper(value: $coffeeAmount, in: 1...20) {
                    if coffeeAmount == 1 {
                        Text("1 cup")
                    } else {
                        Text("\(coffeeAmount) cups")
                    }
                }
            }
            .navigationBarTitle("BetterRest")
            .navigationBarItems(trailing:
                Button(action: calculateBedtime) {
                    Text("Calculate")
                }
            )
        }
    }
}

func calculateBedtime() {

}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Then I tried to run it on my iphone 6s and iPhone 8 plus Simulator, both got the same error.

https://imgur.com/a/ChUwsVB

Is anything I was doing wrong?

and how can I fix the problem ?

Thanks in advance.

2      

The problem is here:

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

You forgot the . in front of the font() modifier.

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.