Stand nach Tag 1
This commit is contained in:
parent
6edf869fe8
commit
8eef26c4a4
8 changed files with 75 additions and 137 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
|
|
@ -4,6 +4,9 @@ import SwiftUI
|
||||||
@main
|
@main
|
||||||
struct TheSwiftWeek: App {
|
struct TheSwiftWeek: App {
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
|
WindowGroup {
|
||||||
|
Text("Moin")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
13
BikeView.swift
Normal file
13
BikeView.swift
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct BikeView: View {
|
||||||
|
var body: some View {
|
||||||
|
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
BikeView()
|
||||||
|
}
|
||||||
38
Models.swift
38
Models.swift
|
|
@ -1,3 +1,39 @@
|
||||||
|
import Playgrounds
|
||||||
|
import Foundation
|
||||||
|
|
||||||
let a=""
|
|
||||||
|
|
||||||
|
protocol Vehicle {
|
||||||
|
var name: String { get }
|
||||||
|
var color: String { get set }
|
||||||
|
}
|
||||||
|
struct Train: Vehicle {
|
||||||
|
var name: String
|
||||||
|
var color: String
|
||||||
|
var delay: Int
|
||||||
|
var content: Bike
|
||||||
|
|
||||||
|
init(
|
||||||
|
name: String = "ICE",
|
||||||
|
color: String = "white",
|
||||||
|
delay: Int = 0,
|
||||||
|
@BikeBuilder content: @escaping () -> Bike
|
||||||
|
) {
|
||||||
|
self.name = name
|
||||||
|
self.color = color
|
||||||
|
self.delay = delay
|
||||||
|
self.content = content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct Bike: Vehicle, CustomStringConvertible {
|
||||||
|
var name: String
|
||||||
|
var color: String
|
||||||
|
var description: String { name + " is " + color }
|
||||||
|
|
||||||
|
var price: some Equatable {
|
||||||
|
"FREE"
|
||||||
|
}
|
||||||
|
static let trek = Bike(name: "Trek", color: "green")
|
||||||
|
func emptyBasket() {
|
||||||
|
print("emptied", Date())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,88 +1,18 @@
|
||||||
// https://carrascomolina.com
|
|
||||||
import Playgrounds
|
import Playgrounds
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
protocol Vehicle {
|
|
||||||
// name ist read-only
|
|
||||||
var name: String {get}
|
|
||||||
var color: String {get set}
|
|
||||||
}
|
|
||||||
protocol Garage {
|
|
||||||
associatedtype V: Vehicle
|
|
||||||
func park(vehicle: V)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BikeGarage: Garage {
|
|
||||||
|
|
||||||
|
|
||||||
func park(vehicle: Bike){
|
|
||||||
vehicle.emptyBasket()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Train: Vehicle {
|
|
||||||
var name: String
|
|
||||||
var color = "white"
|
|
||||||
var delay = 0 // nicht im protocol
|
|
||||||
|
|
||||||
func delayed(minutes: Int) -> Train {
|
|
||||||
var train = self
|
|
||||||
train.delay = minutes
|
|
||||||
return train
|
|
||||||
}
|
|
||||||
|
|
||||||
let makeSomeNoise = { (noise: String) -> String in
|
|
||||||
noise.uppercased()
|
|
||||||
}
|
|
||||||
var content: () -> Vehicle
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ICE: Vehicle {
|
|
||||||
var name = "ICE"
|
|
||||||
var color = "white"
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Bike: Vehicle, CustomStringConvertible {
|
|
||||||
var name: String
|
|
||||||
var color: String
|
|
||||||
// newValue ist ein special keyword
|
|
||||||
func emptyBasket(){
|
|
||||||
print(description + " korb ausgekippt", Date())
|
|
||||||
}
|
|
||||||
var description: String {
|
|
||||||
set { name = newValue }
|
|
||||||
get {"A \(price)€ bike called \(name) and it is \(color)." }}
|
|
||||||
static let trek = Bike(name: "Trek", color: "red" )
|
|
||||||
|
|
||||||
var price: some Equatable {
|
|
||||||
// switch (Int.random(in: 1...3)) {
|
|
||||||
// case 1:
|
|
||||||
// Double.random(in: 1000...9000)
|
|
||||||
// case 2:
|
|
||||||
// "Free"
|
|
||||||
// default:
|
|
||||||
Int.random(in: 100...900)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var bike = Bike.trek
|
var bike = Bike.trek
|
||||||
let train = Train(name: "RadZug", content: { Bike.trek })
|
let train = Train { Bike.trek }
|
||||||
|
|
||||||
#Playground {
|
|
||||||
// var greeting = "Hallo Playground"
|
|
||||||
|
|
||||||
// var train = Train(name:"ICE")
|
|
||||||
// bike.description
|
|
||||||
// bike.description = "Mein Rad"
|
|
||||||
// bike.description
|
|
||||||
|
|
||||||
// train
|
@resultBuilder struct BikeBuilder {
|
||||||
// train.delayed(minutes: 23)
|
static func buildBlock(_ components: Bike) -> Bike {
|
||||||
// BikeGarage().park(vehicle: bike)
|
components
|
||||||
// print( bike)
|
}
|
||||||
// train.makeSomeNoise("huhu")
|
}
|
||||||
// // write code here
|
|
||||||
|
#Playground {
|
||||||
train.content().name
|
// bike.price
|
||||||
|
// train.makeSomeNoise("Choo Choo!")
|
||||||
|
train.content.name
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A882E92EEA900271E8D /* Playground.swift */; };
|
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A882E92EEA900271E8D /* Playground.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 */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
|
@ -19,6 +20,7 @@
|
||||||
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>"; };
|
||||||
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>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
|
@ -38,6 +40,7 @@
|
||||||
0CC14A842E92EC7A00271E8D /* App.swift */,
|
0CC14A842E92EC7A00271E8D /* App.swift */,
|
||||||
FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */,
|
FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */,
|
||||||
0CC14A882E92EEA900271E8D /* Playground.swift */,
|
0CC14A882E92EEA900271E8D /* Playground.swift */,
|
||||||
|
FBA6FA612EA76AAD00C373EC /* BikeView.swift */,
|
||||||
FBA6FA5D2EA63EA300C373EC /* Models.swift */,
|
FBA6FA5D2EA63EA300C373EC /* Models.swift */,
|
||||||
0CC14A772E92EC4700271E8D /* Products */,
|
0CC14A772E92EC4700271E8D /* Products */,
|
||||||
);
|
);
|
||||||
|
|
@ -127,6 +130,7 @@
|
||||||
FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */,
|
FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */,
|
||||||
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */,
|
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */,
|
||||||
0CC14A872E92EC7B00271E8D /* App.swift in Sources */,
|
0CC14A872E92EC7B00271E8D /* App.swift in Sources */,
|
||||||
|
FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -7,65 +7,17 @@
|
||||||
<BreakpointProxy
|
<BreakpointProxy
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||||
<BreakpointContent
|
<BreakpointContent
|
||||||
uuid = "60F4FEF4-4F42-4C29-B795-B68DFA0CB921"
|
uuid = "B8EA1D18-A70B-45BA-91B0-542F11641B66"
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Playground.swift"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "40"
|
|
||||||
endingLineNumber = "40"
|
|
||||||
landmarkName = "ICE"
|
|
||||||
landmarkType = "14">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "1AD49130-FF07-483D-BB89-C32BFEA100E5"
|
|
||||||
shouldBeEnabled = "Yes"
|
shouldBeEnabled = "Yes"
|
||||||
ignoreCount = "0"
|
ignoreCount = "0"
|
||||||
continueAfterRunningActions = "No"
|
continueAfterRunningActions = "No"
|
||||||
filePath = "App.swift"
|
filePath = "BikeView.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "4"
|
startingLineNumber = "1"
|
||||||
endingLineNumber = "4"
|
endingLineNumber = "1"
|
||||||
landmarkName = "TheSwiftWeek"
|
landmarkName = "unknown"
|
||||||
landmarkType = "14">
|
landmarkType = "0">
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "85CFA9E8-BF14-4860-9D61-E8435BD1A73A"
|
|
||||||
shouldBeEnabled = "Yes"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "App.swift"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "6"
|
|
||||||
endingLineNumber = "6"
|
|
||||||
landmarkName = "body"
|
|
||||||
landmarkType = "24">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "560FB38F-4034-4C49-A74B-4B760E1C2FF6"
|
|
||||||
shouldBeEnabled = "Yes"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "Playground.swift"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "10"
|
|
||||||
endingLineNumber = "10"
|
|
||||||
landmarkName = "Garage"
|
|
||||||
landmarkType = "5">
|
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
</Breakpoints>
|
</Breakpoints>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue