diff --git a/BikeView.swift b/BikeView.swift index b77257f..0d82475 100644 --- a/BikeView.swift +++ b/BikeView.swift @@ -7,7 +7,7 @@ struct BikeView: View { var bike = Bike(name: "Fahrrad", color: "lila") var body: some View { Text(bike.description) - Text(bike.name) + Text(String(describing: bike)) ForEach(1...5, id: \.self) { number in Text(bike.color + " " + String(number)) } diff --git a/Extentions.swift b/Extentions.swift new file mode 100644 index 0000000..9a30829 --- /dev/null +++ b/Extentions.swift @@ -0,0 +1,3 @@ +import Foundation + + diff --git a/Models.swift b/Models.swift index 257319e..5531f26 100644 --- a/Models.swift +++ b/Models.swift @@ -6,12 +6,12 @@ protocol Vehicle { var name: String { get } var color: String { get set } } -struct Train: Vehicle { +struct Train: Vehicle, CustomStringConvertible { var name: String var color: String var delay: Int var content: Bike - + var description: String { "Zug \(name) mit \(content) hat \(delay) Minuten Verspätung" } init( name: String = "ICE", color: String = "white", diff --git a/TheSwiftWeek.xcodeproj/project.pbxproj b/TheSwiftWeek.xcodeproj/project.pbxproj index ce5c72d..0071542 100644 --- a/TheSwiftWeek.xcodeproj/project.pbxproj +++ b/TheSwiftWeek.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 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 */; }; + FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA632EA7715000C373EC /* Extentions.swift */; }; + FBA6FA662EA7725A00C373EC /* TrainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA652EA7725A00C373EC /* TrainView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -21,6 +23,8 @@ 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 = ""; }; + FBA6FA632EA7715000C373EC /* Extentions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extentions.swift; sourceTree = ""; }; + FBA6FA652EA7725A00C373EC /* TrainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrainView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -37,10 +41,12 @@ 0CC14A6D2E92EC4700271E8D = { isa = PBXGroup; children = ( + FBA6FA632EA7715000C373EC /* Extentions.swift */, 0CC14A842E92EC7A00271E8D /* App.swift */, FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */, 0CC14A882E92EEA900271E8D /* Playground.swift */, FBA6FA612EA76AAD00C373EC /* BikeView.swift */, + FBA6FA652EA7725A00C373EC /* TrainView.swift */, FBA6FA5D2EA63EA300C373EC /* Models.swift */, 0CC14A772E92EC4700271E8D /* Products */, ); @@ -128,7 +134,9 @@ buildActionMask = 2147483647; files = ( FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */, + FBA6FA662EA7725A00C373EC /* TrainView.swift in Sources */, 0CC14A892E92EEA900271E8D /* Playground.swift in Sources */, + FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */, 0CC14A872E92EC7B00271E8D /* App.swift in Sources */, FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */, ); diff --git a/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate b/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate index 1bbd38b..250bf6a 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 new file mode 100644 index 0000000..85bee15 --- /dev/null +++ b/TrainView.swift @@ -0,0 +1,19 @@ + + +import SwiftUI + + +struct TrainView: View { + var train = Train(name: "RE3412", color: "beige", delay: 45){ Bike.trek} + var train2 = Train(name: "RE1423", delay: 5){ Bike(name: "Bulls", color: "orange")} + + var body: some View { + Text(train.description) + Text(train2.description) + + } +} + +#Preview { + TrainView() +}