diff --git a/App.swift b/App.swift index e5d4ff3..7bbb898 100644 --- a/App.swift +++ b/App.swift @@ -9,9 +9,12 @@ struct TheSwiftWeek: App { var body: some Scene { WindowGroup { VStack{ - Text(.myVehicle) - TrainView(train: train) - TrainView(train: train2) + + + Text(.myVehicle) + TrainView(train: train) + TrainView(train: train2) + Spacer() } } diff --git a/ContentView.swift b/ContentView.swift new file mode 100644 index 0000000..0c22fca --- /dev/null +++ b/ContentView.swift @@ -0,0 +1,31 @@ + + +import SwiftUI + +enum TabLabel: String { + case bikes + case trains + case cars + var title: String { rawValue.capitalized } +} + + +struct ContentView: View { + var body: some View { + TabView { + Tab(TabLabel.bikes.title, systemImage: "bicycle") { + BikeView() + } + Tab(TabLabel.bikes.title, systemImage: "train.side.front.car") { + TrainView() + } + Tab("drücken", systemImage: "car") { + SwapperView() + } + } + } +} + +#Preview { + ContentView() +} diff --git a/Localizable.xcstrings b/Localizable.xcstrings index e3396ff..6e4d3bc 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -1,6 +1,14 @@ { "sourceLanguage" : "en", "strings" : { + "drücken" : { + "comment" : "A tab label for a tab that prints something.", + "isCommentAutoGenerated" : true + }, + "Hello, World!" : { + "comment" : "A simple text view with padding applied to it.", + "isCommentAutoGenerated" : true + }, "My Vehicle" : { "extractionState" : "manual", "localizations" : { @@ -18,6 +26,22 @@ } } }, + "Show Alert" : { + "comment" : "A button that triggers an alert when pressed.", + "isCommentAutoGenerated" : true + }, + "Swapping %@ <-> %@" : { + "comment" : "A label displaying the current state of the swap operation, showing the values of the two variables before and after the swap.", + "isCommentAutoGenerated" : true, + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Swapping %1$@ <-> %2$@" + } + } + } + }, "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, @@ -48,6 +72,18 @@ } } } + }, + "Vorher %@ <-> %@" : { + "comment" : "Displays two text fields with the text \"Vorher\" and \"Nachher\" followed by a button that, when pressed, swaps the text in the two fields.", + "isCommentAutoGenerated" : true, + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Vorher %1$@ <-> %2$@" + } + } + } } }, "version" : "1.1" diff --git a/PaddingView.swift b/PaddingView.swift new file mode 100644 index 0000000..70673e5 --- /dev/null +++ b/PaddingView.swift @@ -0,0 +1,11 @@ +import SwiftUI + +struct PaddingView: View { + var body: some View { + Text("Hello, World!") + .padding() + } +} +#Preview { + PaddingView() +} diff --git a/SwapperView.swift b/SwapperView.swift new file mode 100644 index 0000000..4124b87 --- /dev/null +++ b/SwapperView.swift @@ -0,0 +1,44 @@ +import SwiftUI + +struct SwapperView: View{ + + @State var sw = Swapper(a: "Apfel", b: "Banana") + @State var a = "Apfel" + @State var b = "Banane" + + + func tausche(){ + let tmp = a + a = b + b = tmp + } + + var body: some View { + VStack { + Text("Vorher \(a) <-> \(b)") + + Button("Show Alert") { + print("Hello, World!") + tausche() + sw.tausche() + } + Text("Swapping \(sw.a) <-> \(sw.b)") + + } + } +} + +struct Swapper { + var a: T + var b: T + + + mutating func tausche(){ + let tmp = a + a = b + b = tmp + } +} +#Preview { + SwapperView() +} diff --git a/TheSwiftWeek.xcodeproj/project.pbxproj b/TheSwiftWeek.xcodeproj/project.pbxproj index 7c61cda..573c905 100644 --- a/TheSwiftWeek.xcodeproj/project.pbxproj +++ b/TheSwiftWeek.xcodeproj/project.pbxproj @@ -11,6 +11,9 @@ 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 */; }; + FBA00D712EA7A839006F8B9A /* PaddingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D702EA7A830006F8B9A /* PaddingView.swift */; }; + FBA00D732EA7A96C006F8B9A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D722EA7A96C006F8B9A /* ContentView.swift */; }; + FBA00D752EA7ACE1006F8B9A /* SwapperView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D742EA7ACDD006F8B9A /* SwapperView.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 */; }; @@ -24,6 +27,9 @@ 0CC14A882E92EEA900271E8D /* Playground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Playground.swift; sourceTree = ""; }; FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = ""; }; FBA00D6E2EA78850006F8B9A /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; + FBA00D702EA7A830006F8B9A /* PaddingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddingView.swift; sourceTree = ""; }; + FBA00D722EA7A96C006F8B9A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + FBA00D742EA7ACDD006F8B9A /* SwapperView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwapperView.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 = ""; }; @@ -45,9 +51,12 @@ 0CC14A6D2E92EC4700271E8D = { isa = PBXGroup; children = ( + FBA00D742EA7ACDD006F8B9A /* SwapperView.swift */, + FBA00D702EA7A830006F8B9A /* PaddingView.swift */, FBA00D6E2EA78850006F8B9A /* Color.swift */, FBA6FA632EA7715000C373EC /* Extentions.swift */, 0CC14A842E92EC7A00271E8D /* App.swift */, + FBA00D722EA7A96C006F8B9A /* ContentView.swift */, FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */, 0CC14A882E92EEA900271E8D /* Playground.swift */, FBA6FA612EA76AAD00C373EC /* BikeView.swift */, @@ -143,10 +152,13 @@ files = ( FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */, FBA6FA662EA7725A00C373EC /* TrainView.swift in Sources */, + FBA00D752EA7ACE1006F8B9A /* SwapperView.swift in Sources */, 0CC14A892E92EEA900271E8D /* Playground.swift in Sources */, FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */, 0CC14A872E92EC7B00271E8D /* App.swift in Sources */, + FBA00D732EA7A96C006F8B9A /* ContentView.swift in Sources */, FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */, + FBA00D712EA7A839006F8B9A /* PaddingView.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 7206961..f29ddb1 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