Monday, June 17, 2024

🎉 I just finished Day 11 of the #100DaysOfSwiftUI at https://www.hackingwithswift.com/100/swiftui/11

 ðŸŽ‰ I just finished Day 11 of the #100DaysOfSwiftUI at https://www.hackingwithswift.com/100/swiftui/11

struct Car {

    let model: String

    let numberOfSeats: Int

    private(set) var currentGear = 1

        

    enum GearDirection {

        case up, down, neutral

    }

    

    public mutating func changeGear(_ direction: GearDirection) {

        switch direction {

        case .down: currentGear -= 1

            if currentGear < 1 {currentGear = 1}

        case .up: currentGear += 1

            if currentGear > 10 {currentGear = 10}

        case .neutral:

            currentGear = 1

        }

        print("The \(model) is in gear: \(currentGear)")

    }

}


var thecar = Car(model: "Mazda", numberOfSeats: 5, currentGear: 1)

thecar.changeGear(.up)

thecar.changeGear(.neutral)

thecar.changeGear(.down)


No comments:

Post a Comment

🎉 I just finished Day 19 of the #100DaysOfSwiftUI at https://www.hackingwithswift.com/100/swiftui/19

 Made a Temperature Converter App for the SwiftUI Challenge Day!