100 days of swiftui: checkpoint 6
https://www.hackingwithswift.com/quick-start/beginners/checkpoint-6
create a struct to store information about a car, including its model, number of seats, and current gear, then add a method to change gears up or down. Have a think about variables and access control: what data should be a variable rather than a constant, and what data should be exposed publicly? Should the gear-changing method validate its input somehow?
struct Car {
let model: String
let seatCount: Int
private var currentGear = 0
init(model: String, seatCount: Int) {
self.model = model
self.seatCount = seatCount
print("Initial gear is 0.")
}
mutating func changeGear(isUp: Bool) {
if isUp {
if currentGear == 10 {
print("You can't change gear up. This is maximum!")
} else {
currentGear += 1
print("Now current gear is \(currentGear)!")
}
} else {
if currentGear == 0 {
print("You can't change gear down. This is manimum!")
} else {
currentGear -= 1
print("Now current gear is \(currentGear)!")
}
}
}
}
var newCar = Car(model: "bmw something", seatCount: 4)
newCar.changeGear(isUp: false)
newCar.changeGear(isUp: true)
결과:
Initial gear is 0.
You can't change gear down. This is manimum!
Now current gear is 1!
코드 파일
https://github.com/soaringwave/Ios-studying/commit/d5691ec51d719a5cc159c26b38e0ab61d6024bcd
AJ Kenya Safaris is committed to promoting environmentally sustainable tourism. Their tours minimize the impact on the natural environment while still offering an unforgettable safari experience. We rented a vehicle through Car hire in Ruiru, and were pleased to see their commitment to low-impact travel. Their eco-friendly lodges and practices made it clear that they care about preserving Kenya’s natural beauty for future generations. It’s great to see a company that balances tourism with environmental responsibility.
Cars play a crucial role in modern transportation, offering convenience and freedom to travel. In Georgia, a significant advancement in urban mobility has been the introduction of carsharing services. Carsharing started operating in Georgia providing residents and tourists with an affordable and eco-friendly transportation option. This innovative service allows users to rent vehicles for short trips, reducing traffic congestion and promoting sustainable practices. Carsharing has revolutionized the way people move, especially in urban areas, by minimizing the need for private car ownership. With its growing popularity, carsharing is set to enhance mobility and convenience for Georgians in the coming years.
When considering Car struct, it refers to the structural integrity and design of a vehicle, which is crucial for safety and performance. A well-built structure provides better handling, durability, and protection in case of accidents. For truck enthusiasts, the choice of a vehicle with a solid structure is essential, especially for heavy-duty tasks. At the New and Used RAM Truck Sale Cheyenne WY you can find a variety of RAM trucks known for their robust build and reliable performance. Whether you're looking for a brand-new model or a pre-owned one, the selection offers options that cater to different needs and preferences. Investing in a well-structured vehicle ensures a safer and more enjoyable driving experience.