Schulung_iOS/Models.swift
2025-10-22 13:24:48 +02:00

70 lines
1.8 KiB
Swift

import Foundation
import SwiftUI
protocol Vehicle: Identifiable {
var name: String { get }
var color: Color { get set }
}
extension Vehicle {
var id: UUID {UUID()}
}
//protocol TabContent: View {
protocol TabContent: View {
init()
static var title: String { get }
static var image: String { get }
}
extension TabContent {
var id: UUID {UUID()}
}
struct Train: @MainActor Vehicle, CustomStringConvertible , CustomLocalizedStringResourceConvertible {
var name: String
var color: Color
var delay: Int
var content: Bike
var description: String { "Zug \(name) hat \(delay) Minuten Verspätung" }
var localizedStringResource: LocalizedStringResource {
"Train \(name) has ^[\(delay) minute](inflect: true) delay."
}
// init(describing obj: CustomLocalizedStringResourceConvertible){
// self.init(describing: obj.localizedStringResource)
// }
init(
name: String = "ICE",
color: Color = .red,
delay: Int = 0,
@BikeBuilder content: @escaping () -> Bike
) {
self.name = name
self.color = Color.yellow
self.delay = delay
self.content = content()
}
}
struct Bike: @MainActor Vehicle, CustomStringConvertible {
var name: String
var price: Double
var color: Color
// var description: String { name + " is " + color }
var description: String {"\(name) is \(color)" }
static let trek = Bike(name: "Trek", price: 12.98,color: .red )
func emptyBasket() {
print("emptied", Date())
}
static let all = [
Bike(name: "Specialized",price: 100000.00, color: .purple ),
Bike(name: "Giant",price: 120000.00, color: .red ),
Bike(name: "Cannondale",price: 110000.00, color: .green )
]
}