diff --git a/App.swift b/App.swift index ea618a1..e5d4ff3 100644 --- a/App.swift +++ b/App.swift @@ -3,9 +3,17 @@ import SwiftUI @main struct TheSwiftWeek: App { + var train = Train(name: "RE3412", color: Color.yellow, delay: 2 ){ Bike.trek} + var train2 = Train(name: "RE1423", delay: 1){ Bike(name: "Bulls", price: 199.90, color: Color.indigo )} + var body: some Scene { WindowGroup { - BikeView() + VStack{ + Text(.myVehicle) + TrainView(train: train) + TrainView(train: train2) + } + } } } diff --git a/BikeView.swift b/BikeView.swift index 0d82475..2f366a1 100644 --- a/BikeView.swift +++ b/BikeView.swift @@ -4,12 +4,14 @@ import SwiftUI struct BikeView: View { - var bike = Bike(name: "Fahrrad", color: "lila") + var bike = Bike(name: "Fahrrad", price: 11.31, color: Color.cyan) var body: some View { - Text(bike.description) - Text(String(describing: bike)) - ForEach(1...5, id: \.self) { number in - Text(bike.color + " " + String(number)) + VStack{ + Label(bike.name, systemImage: "bicycle") + .foregroundStyle(.white) + .padding(5) + .background(bike.color) + } } diff --git a/Color.swift b/Color.swift new file mode 100644 index 0000000..e544d7b --- /dev/null +++ b/Color.swift @@ -0,0 +1,9 @@ + + + +enum Farbe { + case red + case green + case yellow +} +//var color: Color { get } diff --git a/Localizable.xcstrings b/Localizable.xcstrings index ae21f3e..e3396ff 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -18,8 +18,21 @@ } } }, + "Train %@ has ^[%lld minute](inflect: true) delay." : { + "comment" : "A localized string resource describing a train. The first argument is the name of the train. The second argument is the delay in minutes.", + "isCommentAutoGenerated" : true, + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Train %1$@ has ^[%2$lld minute](inflect: true) delay." + } + } + } + }, "Train %@ with %@ has ^[%lld minute](inflect: true) delay." : { "comment" : "A localized string resource that describes a train with a bike. The first argument is the name of the train. The second argument is the description of the bike.", + "extractionState" : "stale", "isCommentAutoGenerated" : true, "localizations" : { "de" : { diff --git a/Models.swift b/Models.swift index 8a82c6d..9bff369 100644 --- a/Models.swift +++ b/Models.swift @@ -1,19 +1,19 @@ import Foundation - +import SwiftUI protocol Vehicle { var name: String { get } - var color: String { get set } + var color: Color { get set } } struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceConvertible { var name: String - var color: String + var color: Color var delay: Int var content: Bike - var description: String { "Zug \(name) mit \(content) hat \(delay) Minuten Verspätung" } + var description: String { "Zug \(name) hat \(delay) Minuten Verspätung" } var localizedStringResource: LocalizedStringResource { - "Train \(name) with \(content) has ^[\(delay) minute](inflect: true) delay." + "Train \(name) has ^[\(delay) minute](inflect: true) delay." } // init(describing obj: CustomLocalizedStringResourceConvertible){ @@ -22,12 +22,12 @@ struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceCo init( name: String = "ICE", - color: String = "white", + color: Color = .red, delay: Int = 0, @BikeBuilder content: @escaping () -> Bike ) { self.name = name - self.color = color + self.color = Color.yellow self.delay = delay self.content = content() } @@ -35,13 +35,14 @@ struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceCo struct Bike: Vehicle, CustomStringConvertible { var name: String - var color: String - var description: String { name + " is " + color } + var price: Double + var color: Color +// var description: String { name + " is " + color } + var description: String {"\(name) is \(color)" } - var price: some Equatable { - "FREE" - } - static let trek = Bike(name: "Trek", color: "green") + + + static let trek = Bike(name: "Trek", price: 12.98,color: .red ) func emptyBasket() { print("emptied", Date()) } diff --git a/TheSwiftWeek.xcodeproj/project.pbxproj b/TheSwiftWeek.xcodeproj/project.pbxproj index 3b991ca..7c61cda 100644 --- a/TheSwiftWeek.xcodeproj/project.pbxproj +++ b/TheSwiftWeek.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 0CC14A872E92EC7B00271E8D /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A842E92EC7A00271E8D /* App.swift */; }; 0CC14A892E92EEA900271E8D /* Playground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A882E92EEA900271E8D /* Playground.swift */; }; FBA00D6D2EA78411006F8B9A /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */; }; + FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D6E2EA78850006F8B9A /* Color.swift */; }; FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA5D2EA63EA300C373EC /* Models.swift */; }; FBA6FA602EA66C2E00C373EC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */; }; FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA612EA76AAD00C373EC /* BikeView.swift */; }; @@ -22,6 +23,7 @@ 0CC14A842E92EC7A00271E8D /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = ""; }; 0CC14A882E92EEA900271E8D /* Playground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Playground.swift; sourceTree = ""; }; FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = ""; }; + FBA00D6E2EA78850006F8B9A /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; FBA6FA5D2EA63EA300C373EC /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = ""; }; FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; FBA6FA612EA76AAD00C373EC /* BikeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BikeView.swift; sourceTree = ""; }; @@ -43,6 +45,7 @@ 0CC14A6D2E92EC4700271E8D = { isa = PBXGroup; children = ( + FBA00D6E2EA78850006F8B9A /* Color.swift */, FBA6FA632EA7715000C373EC /* Extentions.swift */, 0CC14A842E92EC7A00271E8D /* App.swift */, FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */, @@ -143,6 +146,7 @@ 0CC14A892E92EEA900271E8D /* Playground.swift in Sources */, FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */, 0CC14A872E92EC7B00271E8D /* App.swift in Sources */, + FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */, FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate b/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate index f272ce8..7206961 100644 Binary files a/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate and b/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TrainView.swift b/TrainView.swift index 5157562..99672b2 100644 --- a/TrainView.swift +++ b/TrainView.swift @@ -4,14 +4,22 @@ import SwiftUI struct TrainView: View { - var train = Train(name: "RE3412", color: "beige", delay: 2 ){ Bike.trek} - var train2 = Train(name: "RE1423", delay: 1){ Bike(name: "Bulls", color: "orange")} + var train = Train(name: "RE3412", color: Color.yellow, delay: 2 ){ Bike.trek} + var train2 = Train(name: "RE1423", delay: 1){ Bike(name: "Bulls", price: 1.90, color: Color.red)} + var body: some View { - Text(describing: train) - Text(describing: train2) - Text(train.localizedStringResource) - Text(.myVehicle) + VStack{ + + + Image(systemName: "train") + // train.color + HStack{ + Text(train.localizedStringResource) + BikeView(bike: train.content) + } + // train2.color + } } }