diff --git a/.DS_Store b/.DS_Store index 9724233..bea1c48 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/App.swift b/App.swift index 3ab57d1..7952d41 100644 --- a/App.swift +++ b/App.swift @@ -4,6 +4,9 @@ import SwiftUI @main struct TheSwiftWeek: App { var body: some Scene { + WindowGroup { + Text("Moin") + } } } - + diff --git a/BikeView.swift b/BikeView.swift new file mode 100644 index 0000000..9a898f4 --- /dev/null +++ b/BikeView.swift @@ -0,0 +1,13 @@ + + +import SwiftUI + +struct BikeView: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +#Preview { + BikeView() +} diff --git a/Models.swift b/Models.swift index d23aece..257319e 100644 --- a/Models.swift +++ b/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()) + } +} diff --git a/Playground.swift b/Playground.swift index d8fc281..5933237 100644 --- a/Playground.swift +++ b/Playground.swift @@ -1,88 +1,18 @@ -// https://carrascomolina.com import Playgrounds 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 -let train = Train(name: "RadZug", content: { Bike.trek }) - -#Playground { - // var greeting = "Hallo Playground" - - // var train = Train(name:"ICE") - // bike.description - // bike.description = "Mein Rad" - // bike.description +let train = Train { Bike.trek } -// train -// train.delayed(minutes: 23) -// BikeGarage().park(vehicle: bike) -// print( bike) -// train.makeSomeNoise("huhu") -// // write code here - - train.content().name +@resultBuilder struct BikeBuilder { + static func buildBlock(_ components: Bike) -> Bike { + components + } +} + +#Playground { +// bike.price +// train.makeSomeNoise("Choo Choo!") + train.content.name } diff --git a/TheSwiftWeek.xcodeproj/project.pbxproj b/TheSwiftWeek.xcodeproj/project.pbxproj index 2286949..ce5c72d 100644 --- a/TheSwiftWeek.xcodeproj/project.pbxproj +++ b/TheSwiftWeek.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 0CC14A892E92EEA900271E8D /* Playground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A882E92EEA900271E8D /* Playground.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 */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -19,6 +20,7 @@ 0CC14A882E92EEA900271E8D /* Playground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Playground.swift; sourceTree = ""; }; 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 = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -38,6 +40,7 @@ 0CC14A842E92EC7A00271E8D /* App.swift */, FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */, 0CC14A882E92EEA900271E8D /* Playground.swift */, + FBA6FA612EA76AAD00C373EC /* BikeView.swift */, FBA6FA5D2EA63EA300C373EC /* Models.swift */, 0CC14A772E92EC4700271E8D /* Products */, ); @@ -127,6 +130,7 @@ FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */, 0CC14A892E92EEA900271E8D /* Playground.swift in Sources */, 0CC14A872E92EC7B00271E8D /* App.swift in Sources */, + FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate b/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate index 62ca249..697d3da 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/TheSwiftWeek.xcodeproj/xcuserdata/rohing73.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/TheSwiftWeek.xcodeproj/xcuserdata/rohing73.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index c6ce461..3488f34 100644 --- a/TheSwiftWeek.xcodeproj/xcuserdata/rohing73.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/TheSwiftWeek.xcodeproj/xcuserdata/rohing73.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -7,65 +7,17 @@ - - - - - - - - - - - - + startingLineNumber = "1" + endingLineNumber = "1" + landmarkName = "unknown" + landmarkType = "0">