TrainView
This commit is contained in:
parent
37ae8487be
commit
8fe5a49f52
6 changed files with 33 additions and 3 deletions
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
3
Extentions.swift
Normal file
3
Extentions.swift
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import Foundation
|
||||
|
||||
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 = "<group>"; };
|
||||
FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
FBA6FA612EA76AAD00C373EC /* BikeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BikeView.swift; sourceTree = "<group>"; };
|
||||
FBA6FA632EA7715000C373EC /* Extentions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extentions.swift; sourceTree = "<group>"; };
|
||||
FBA6FA652EA7725A00C373EC /* TrainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrainView.swift; sourceTree = "<group>"; };
|
||||
/* 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 */,
|
||||
);
|
||||
|
|
|
|||
Binary file not shown.
19
TrainView.swift
Normal file
19
TrainView.swift
Normal file
|
|
@ -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()
|
||||
}
|
||||
Loading…
Reference in a new issue