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
|
@main
|
||||||
struct TheSwiftWeek: App {
|
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 {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
BikeView()
|
VStack{
|
||||||
|
Text(.myVehicle)
|
||||||
|
TrainView(train: train)
|
||||||
|
TrainView(train: train2)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@ import SwiftUI
|
||||||
|
|
||||||
|
|
||||||
struct BikeView: View {
|
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 {
|
var body: some View {
|
||||||
Text(bike.description)
|
VStack{
|
||||||
Text(String(describing: bike))
|
Label(bike.name, systemImage: "bicycle")
|
||||||
ForEach(1...5, id: \.self) { number in
|
.foregroundStyle(.white)
|
||||||
Text(bike.color + " " + String(number))
|
.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." : {
|
"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.",
|
"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,
|
"isCommentAutoGenerated" : true,
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"de" : {
|
"de" : {
|
||||||
|
|
|
||||||
27
Models.swift
27
Models.swift
|
|
@ -1,19 +1,19 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
protocol Vehicle {
|
protocol Vehicle {
|
||||||
var name: String { get }
|
var name: String { get }
|
||||||
var color: String { get set }
|
var color: Color { get set }
|
||||||
}
|
}
|
||||||
struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceConvertible {
|
struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceConvertible {
|
||||||
var name: String
|
var name: String
|
||||||
var color: String
|
var color: Color
|
||||||
var delay: Int
|
var delay: Int
|
||||||
var content: Bike
|
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 {
|
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){
|
// init(describing obj: CustomLocalizedStringResourceConvertible){
|
||||||
|
|
@ -22,12 +22,12 @@ struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceCo
|
||||||
|
|
||||||
init(
|
init(
|
||||||
name: String = "ICE",
|
name: String = "ICE",
|
||||||
color: String = "white",
|
color: Color = .red,
|
||||||
delay: Int = 0,
|
delay: Int = 0,
|
||||||
@BikeBuilder content: @escaping () -> Bike
|
@BikeBuilder content: @escaping () -> Bike
|
||||||
) {
|
) {
|
||||||
self.name = name
|
self.name = name
|
||||||
self.color = color
|
self.color = Color.yellow
|
||||||
self.delay = delay
|
self.delay = delay
|
||||||
self.content = content()
|
self.content = content()
|
||||||
}
|
}
|
||||||
|
|
@ -35,13 +35,14 @@ struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceCo
|
||||||
|
|
||||||
struct Bike: Vehicle, CustomStringConvertible {
|
struct Bike: Vehicle, CustomStringConvertible {
|
||||||
var name: String
|
var name: String
|
||||||
var color: String
|
var price: Double
|
||||||
var description: String { name + " is " + color }
|
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", price: 12.98,color: .red )
|
||||||
static let trek = Bike(name: "Trek", color: "green")
|
|
||||||
func emptyBasket() {
|
func emptyBasket() {
|
||||||
print("emptied", Date())
|
print("emptied", Date())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
0CC14A872E92EC7B00271E8D /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A842E92EC7A00271E8D /* App.swift */; };
|
0CC14A872E92EC7B00271E8D /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A842E92EC7A00271E8D /* App.swift */; };
|
||||||
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A882E92EEA900271E8D /* Playground.swift */; };
|
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A882E92EEA900271E8D /* Playground.swift */; };
|
||||||
FBA00D6D2EA78411006F8B9A /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */; };
|
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 */; };
|
FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA5D2EA63EA300C373EC /* Models.swift */; };
|
||||||
FBA6FA602EA66C2E00C373EC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */; };
|
FBA6FA602EA66C2E00C373EC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */; };
|
||||||
FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA612EA76AAD00C373EC /* BikeView.swift */; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
FBA6FA612EA76AAD00C373EC /* BikeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BikeView.swift; sourceTree = "<group>"; };
|
||||||
|
|
@ -43,6 +45,7 @@
|
||||||
0CC14A6D2E92EC4700271E8D = {
|
0CC14A6D2E92EC4700271E8D = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
FBA00D6E2EA78850006F8B9A /* Color.swift */,
|
||||||
FBA6FA632EA7715000C373EC /* Extentions.swift */,
|
FBA6FA632EA7715000C373EC /* Extentions.swift */,
|
||||||
0CC14A842E92EC7A00271E8D /* App.swift */,
|
0CC14A842E92EC7A00271E8D /* App.swift */,
|
||||||
FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */,
|
FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */,
|
||||||
|
|
@ -143,6 +146,7 @@
|
||||||
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */,
|
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */,
|
||||||
FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */,
|
FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */,
|
||||||
0CC14A872E92EC7B00271E8D /* App.swift in Sources */,
|
0CC14A872E92EC7B00271E8D /* App.swift in Sources */,
|
||||||
|
FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */,
|
||||||
FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */,
|
FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -4,14 +4,22 @@ import SwiftUI
|
||||||
|
|
||||||
|
|
||||||
struct TrainView: View {
|
struct TrainView: View {
|
||||||
var train = Train(name: "RE3412", color: "beige", delay: 2 ){ Bike.trek}
|
var train = Train(name: "RE3412", color: Color.yellow, delay: 2 ){ Bike.trek}
|
||||||
var train2 = Train(name: "RE1423", delay: 1){ Bike(name: "Bulls", color: "orange")}
|
var train2 = Train(name: "RE1423", delay: 1){ Bike(name: "Bulls", price: 1.90, color: Color.red)}
|
||||||
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text(describing: train)
|
VStack{
|
||||||
Text(describing: train2)
|
|
||||||
Text(train.localizedStringResource)
|
|
||||||
Text(.myVehicle)
|
Image(systemName: "train")
|
||||||
|
// train.color
|
||||||
|
HStack{
|
||||||
|
Text(train.localizedStringResource)
|
||||||
|
BikeView(bike: train.content)
|
||||||
|
}
|
||||||
|
// train2.color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue