App mit Views
This commit is contained in:
parent
eefe80b984
commit
ad7a4dc6c7
8 changed files with 70 additions and 25 deletions
10
App.swift
10
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
9
Color.swift
Normal file
9
Color.swift
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
|
||||
|
||||
enum Farbe {
|
||||
case red
|
||||
case green
|
||||
case yellow
|
||||
}
|
||||
//var color: Color { get }
|
||||
|
|
@ -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" : {
|
||||
|
|
|
|||
27
Models.swift
27
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())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = "<group>"; };
|
||||
0CC14A882E92EEA900271E8D /* Playground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Playground.swift; sourceTree = "<group>"; };
|
||||
FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
|
||||
FBA00D6E2EA78850006F8B9A /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue