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() } } enum BikeType: String, Codable, CaseIterable, Identifiable { var id: String { rawValue } case unknown case mountain case city case gravel } struct Bike: @MainActor Vehicle, CustomStringConvertible { var name: String var price: Double = Double(Int.random(in: 3...8)*50) - 0.51 var color: Color var type: BikeType = .unknown // 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 var all: [Bike] = [ Bike(name: "Specialized",price: 149.98, color: .purple ), Bike(name: "Giant",price: 129.00, color: .red ), Bike(name: "Cannondale",price: 299.00, color: .green ) ] }