diff --git a/App.swift b/App.swift index 36e6cb0..fc8aae0 100644 --- a/App.swift +++ b/App.swift @@ -14,7 +14,7 @@ struct TheSwiftWeek: App { // ContentView() - UnicycleView() + ContentView() }.modelContainer(for: Unicycle.self) diff --git a/BikeView.swift b/BikeView.swift index 56cff5c..f281efe 100644 --- a/BikeView.swift +++ b/BikeView.swift @@ -8,15 +8,20 @@ struct BikeView: TabContent { static var image = "bicycle" - var bike = Bike(name: "Fahrrad", price: 11.31, color: Color.cyan) + var bike = Bike(name: "Mein Fahrrad ", price: 11.31, color: Color.cyan) var body: some View { - VStack{ + HStack { Label(bike.name, systemImage: "bicycle") .foregroundStyle(.white) .padding(5) .background(bike.color) - + +// .frame(width: 200) +// Spacer() + Text(bike.price, format: .currency( code: "EUR")) + } + } } diff --git a/ListView.swift b/ListView.swift index 6fd3b84..2542f34 100644 --- a/ListView.swift +++ b/ListView.swift @@ -1,56 +1,45 @@ -// -// ListView.swift -// TheSwiftWeek -// -// Created by Ingo Rohlf on 21.10.25. -// - import SwiftUI - -//import Playgrounds -import Foundation -struct ListView: TabContent{ +struct ListView: TabContent { static var title = "List" static var image = "list.bullet" - + static var id = UUID() + @State var bikes = Bike.all + @FocusState var focusedField: UUID? // 1 + var body: some View { List { - Text(bikes[0].name) - Text(bikes[1].name) - Text(bikes[2].name) - } - List(bikes, id: \.name){ bike in - HStack { - - Color(bike.color) - //Circle().fill(style: bike.color) - - - Text(String(bike.name)) - Spacer() + Section { + ForEach($bikes) { $bike in +// HStack { +// TextField("New Bike", text: $bike.name) +// .focused($focusedField, equals: bike.id) +// .textFieldStyle(.roundedBorder) +// Spacer() +// Text("\(bike.price, specifier: "%.2f€")") +// ColorPicker("", selection: $bike.color) +// } + HStack { + BikeView(bike: bike) + Spacer() + ColorPicker("", selection: $bike.color) + + } + } + .onDelete { bikes.remove(atOffsets: $0) } + } footer: { + Button("Add a new Bike") { + let bike = Bike(name: "", color: .white) + bikes.append(bike) +// focusedField = bike.id + } + .frame(maxWidth: .infinity, alignment: .center) } } - List(bikes, id: \.name){ - Text(String($0.price)) - } - - // Weil Vehicle jetzt Identifiable implementiert, geht es ohne id: \.name - List(bikes){ - Text(String($0.name)) - } - } } - -//#Playground { -// var students = ["Bill", "Linus"] -// let size = [1.65, 1.79] -//} - - #Preview { ListView() } diff --git a/Localizable.xcstrings b/Localizable.xcstrings index 2fc7852..30904cf 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -1,16 +1,19 @@ { "sourceLanguage" : "en", "strings" : { + "" : { + + }, "%lld" : { "comment" : "A text element displaying a number. The content of the text element is the integer passed to this view's initializer.", "isCommentAutoGenerated" : true }, - "Add Bike" : { - "comment" : "A button that adds a new bike to the list of bikes.", + "Add a new Bike" : { + "comment" : "A button that allows adding a new bike to the list.", "isCommentAutoGenerated" : true }, - "Add unicycle" : { - "comment" : "A button that adds a new unicycle to the list.", + "Add Bike" : { + "comment" : "A button that adds a new bike to the list of bikes.", "isCommentAutoGenerated" : true }, "Bikes" : { @@ -33,10 +36,6 @@ } } }, - "Einrad von %@" : { - "comment" : "A list item displaying the creation date of a unicycle.", - "isCommentAutoGenerated" : true - }, "Enter Emoji" : { "comment" : "A label for an text field where the user can enter an emoji.", "isCommentAutoGenerated" : true @@ -45,10 +44,6 @@ "comment" : "A word that is displayed when the number is a multiple of 3.", "isCommentAutoGenerated" : true }, - "Hello, World!" : { - "comment" : "A greeting message displayed in the preview.", - "isCommentAutoGenerated" : true - }, "My Vehicle" : { "extractionState" : "manual", "localizations" : { @@ -66,6 +61,10 @@ } } }, + "please update to iOS 26.0 or later" : { + "comment" : "A message to inform the user that they need to update their iOS version to 26.0 or later to use this feature.", + "isCommentAutoGenerated" : true + }, "Show Alert" : { "comment" : "A button that triggers an alert when pressed.", "isCommentAutoGenerated" : true @@ -124,6 +123,10 @@ } } } + }, + "WebView für iOS 26+" : { + "comment" : "A title for the view that displays a web view.", + "isCommentAutoGenerated" : true } }, "version" : "1.1" diff --git a/Models.swift b/Models.swift index 1dd05e3..57972c9 100644 --- a/Models.swift +++ b/Models.swift @@ -48,11 +48,23 @@ struct Train: @MainActor Vehicle, CustomStringConvertible , CustomLocalizedStrin self.content = content() } } +enum BikeType: String, Codable, CaseIterable, Identifiable { + var id: String { rawValue } + + case unknown + case mountain + case city + case gravel +} + struct Bike: @MainActor Vehicle, CustomStringConvertible { var name: String - var price: Double + var price: Double = Double(Int.random(in: 3...8)*50) - 0.51 var color: Color + var type: BikeType = .unknown + + // var description: String { name + " is " + color } var description: String {"\(name) is \(color)" } @@ -63,8 +75,8 @@ struct Bike: @MainActor Vehicle, CustomStringConvertible { print("emptied", Date()) } static var all: [Bike] = [ - Bike(name: "Specialized",price: 100000.00, color: .purple ), - Bike(name: "Giant",price: 120000.00, color: .red ), - Bike(name: "Cannondale",price: 110000.00, color: .green ) + Bike(name: "Specialized",price: 149.98, color: .purple ), + Bike(name: "Giant",price: 129.00, color: .red ), + Bike(name: "Cannondale",price: 299.00, color: .green ) ] } diff --git a/NewUnicycleView.swift b/NewUnicycleView.swift new file mode 100644 index 0000000..050e50f --- /dev/null +++ b/NewUnicycleView.swift @@ -0,0 +1,100 @@ +// +// +//import SwiftUI +//import SwiftData +// +//struct NewUnicycleView: View { +// @Environment(\.modelContext) private var modelContext +// +// @State private var isPresented = false +// @State private var sortOrder = SortDescriptor(\Unicycle.name) +// @State private var search = "" +// +// var body: some View { +// NavigationStack { +// UniListView(filter: search, sort: sortOrder) +// .searchable(text: $search) +// .toolbar { +// ToolbarItem(placement: .topBarLeading) { +// EditButton() +// } +// ToolbarItem(placement: .topBarTrailing) { +// HStack { +// +// Button("Add", systemImage: "plus") { isPresented = true } +// picker +// } +// } +// } +// .sheet(isPresented: $isPresented) { +// UniDetailView(uni: Unicycle()) +// } +// Button("Save 3") { +// try? modelContext.save() +// } +// } +// } +// +// var picker: some View { +// Menu("Sort", systemImage: "arrow.up.arrow.down") { +// Picker("Sort", selection: $sortOrder) { +// Text("Name 55") +// .tag(SortDescriptor(\Unicycle.name)) +// Text("Date") +// .tag(SortDescriptor(\Unicycle.createdAt, order: .reverse)) +// Button("Save") { +// try? modelContext.save() +// } +// } +// +// .pickerStyle(.inline) +// } +// } +// struct UniDetailView: View { +// @Bindable var uni: Unicycle +// @State var color: Color +// @Environment(\.modelContext) private var modelContext +// +// init(uni: Unicycle) { +// self.uni = uni +// _color = State(initialValue: Color(red: uni.red, green: uni.green, blue: uni.blue)) +// } +// +// var body: some View { +// VStack { +// Text(uni.createdAt.description) +// ColorPicker("Color", selection: Binding( +// get: { color as! CGColor }, +// set: { +// color = $0 +//// if let comps = $0.rgbComponents() { +//// uni.red = Double(comps.red) +//// uni.green = Double(comps.green) +//// uni.blue = Double(comps.blue) +//// } +// } +// )) +// TextField("Enter name", text: $uni.name) +// .textFieldStyle(.roundedBorder) +// .padding() +// Button("Save 3") { +// try? modelContext.save() +// +// +// } +// } +// .padding() +// .onChange(of: color) { +// if let comps = color.rgbComponents() { +// uni.red = Double(comps.red) +// uni.green = Double(comps.green) +// uni.blue = Double(comps.blue) +// } +// } +// } +// } +//} +// +//#Preview { +// NewUnicycleView() +//} diff --git a/TheSwiftWeek.xcodeproj/project.pbxproj b/TheSwiftWeek.xcodeproj/project.pbxproj index 2fa8267..5586cb3 100644 --- a/TheSwiftWeek.xcodeproj/project.pbxproj +++ b/TheSwiftWeek.xcodeproj/project.pbxproj @@ -25,6 +25,9 @@ FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA612EA76AAD00C373EC /* BikeView.swift */; }; FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA632EA7715000C373EC /* Extentions.swift */; }; FBA6FA662EA7725A00C373EC /* TrainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA652EA7725A00C373EC /* TrainView.swift */; }; + FBE1A29D2EAA1B4300081638 /* UniView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBE1A29C2EAA1B4300081638 /* UniView.swift */; }; + FBE1A29F2EAA225600081638 /* NewUnicycleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBE1A29E2EAA225600081638 /* NewUnicycleView.swift */; }; + FBE1A2A12EAA340F00081638 /* WebAppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBE1A2A02EAA340F00081638 /* WebAppView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -47,6 +50,9 @@ FBA6FA612EA76AAD00C373EC /* BikeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BikeView.swift; sourceTree = ""; }; FBA6FA632EA7715000C373EC /* Extentions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extentions.swift; sourceTree = ""; }; FBA6FA652EA7725A00C373EC /* TrainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrainView.swift; sourceTree = ""; }; + FBE1A29C2EAA1B4300081638 /* UniView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniView.swift; sourceTree = ""; }; + FBE1A29E2EAA225600081638 /* NewUnicycleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewUnicycleView.swift; sourceTree = ""; }; + FBE1A2A02EAA340F00081638 /* WebAppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebAppView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -63,6 +69,7 @@ 0CC14A6D2E92EC4700271E8D = { isa = PBXGroup; children = ( + FBE1A2A02EAA340F00081638 /* WebAppView.swift */, FBA00D742EA7ACDD006F8B9A /* SwapperView.swift */, FBA00D702EA7A830006F8B9A /* PaddingView.swift */, FBA00D6E2EA78850006F8B9A /* Color.swift */, @@ -75,6 +82,8 @@ FBA6FA612EA76AAD00C373EC /* BikeView.swift */, FB79FE472EA8F74F0011678F /* BikeSwipeView.swift */, FB79FE492EA906CC0011678F /* UnicycleView.swift */, + FBE1A29E2EAA225600081638 /* NewUnicycleView.swift */, + FBE1A29C2EAA1B4300081638 /* UniView.swift */, FB79FE4B2EA9071F0011678F /* Unicycle.swift */, FBA6FA652EA7725A00C373EC /* TrainView.swift */, FB2F07E82EA7CB25002BD499 /* ListView.swift */, @@ -168,6 +177,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + FBE1A29D2EAA1B4300081638 /* UniView.swift in Sources */, FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */, FB79FE482EA8F74F0011678F /* BikeSwipeView.swift in Sources */, FB79FE462EA8CFD20011678F /* RangeView.swift in Sources */, @@ -178,7 +188,9 @@ FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */, FB79FE4A2EA906CC0011678F /* UnicycleView.swift in Sources */, 0CC14A872E92EC7B00271E8D /* App.swift in Sources */, + FBE1A29F2EAA225600081638 /* NewUnicycleView.swift in Sources */, FBA00D732EA7A96C006F8B9A /* ContentView.swift in Sources */, + FBE1A2A12EAA340F00081638 /* WebAppView.swift in Sources */, FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */, FB2F07E92EA7CB25002BD499 /* ListView.swift in Sources */, FBA00D712EA7A839006F8B9A /* PaddingView.swift in Sources */, @@ -327,6 +339,7 @@ INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 18.6; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -358,6 +371,7 @@ INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 18.6; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate b/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate index 2bb7c8f..2678a2d 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 3488f34..23b0a46 100644 --- a/TheSwiftWeek.xcodeproj/xcuserdata/rohing73.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/TheSwiftWeek.xcodeproj/xcuserdata/rohing73.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,22 +3,4 @@ uuid = "543AEB13-B7EA-4C8C-9F73-C23287B3971E" type = "1" version = "2.0"> - - - - - - diff --git a/UniView.swift b/UniView.swift new file mode 100644 index 0000000..9c068e5 --- /dev/null +++ b/UniView.swift @@ -0,0 +1,132 @@ +//import SwiftUI +//import SwiftData +// +////@Model class Unicycle { +//// var createdAt = Date() +//// var name = "" +//// var red = 1.0 +//// var green = 1.0 +//// var blue = 1.0 +//// init() { } // You can't escape this +////} +// +//struct UniView: View { +// @Environment(\.modelContext) private var modelContext +// @Query private var unis: [Unicycle] +// @State private var selection = Set() +// @Environment(\.editMode) private var editMode +// @State private var edit: EditMode = .inactive +// +// var body: some View { +// NavigationStack { +// List(selection: $selection) { +// ForEach(unis) { uni in +// NavigationLink(uni.createdAt.description) { +// UniDetailView(uni: uni) +// } +// } +// .onDelete { indexSet in +// for index in indexSet { +// modelContext.delete(unis[index]) +// } +// } +// } +// .toolbar { +//// ToolbarItem(placement: .topBarLeading) { +// if !unis.isEmpty { EditButton() } +//// } +//// ToolbarItem(placement: .topBarTrailing) { +// if edit == .active { +// if !selectedUnis.isEmpty { +// Button("Delete \(selectedUnis.count)", role: .destructive) { +// // Map selection to models and delete +// for uni in selectedUnis { +// modelContext.delete(uni) +// } +// selection.removeAll() +// } +// .disabled(selection.isEmpty) +// } +// } else { +// Button("Add") { +// modelContext.insert(Unicycle()) +// } +// } +//// } +// } +// .environment(\.editMode, $edit) // <-- Provide the binding +// } +// } +// +// @MainActor +// var selectedUnis: [Unicycle] { +// unis.filter { selection.contains($0.id) } +// } +//} +// +//struct UniDetailView: View { +// @Bindable var uni: Unicycle +// @State var color: Color +// @Environment(\.modelContext) private var modelContext +// +// init(uni: Unicycle) { +// self.uni = uni +// _color = State(initialValue: Color(red: uni.red, green: uni.green, blue: uni.blue)) +// } +// +// var body: some View { +// VStack { +// Text(uni.createdAt.description) +// ColorPicker("Color", selection: Binding( +// get: { color }, +// set: { +// color = $0 +// if let comps = $0.rgbComponents() { +// uni.red = Double(comps.red) +// uni.green = Double(comps.green) +// uni.blue = Double(comps.blue) +// } +// } +// )) +// TextField("Enter name", text: $uni.name) +// .textFieldStyle(.roundedBorder) +// .padding() +// Button("Save 3") { +// try? modelContext.save() +// +// +// } +// } +// .padding() +// .onChange(of: color) { +// if let comps = color.rgbComponents() { +// uni.red = Double(comps.red) +// uni.green = Double(comps.green) +// uni.blue = Double(comps.blue) +// } +// } +// } +//} +// +//extension Color { +// func rgbComponents() -> (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)? { +// // Convert SwiftUI Color to UIColor +// let uiColor = UIColor(self) +// +// var r: CGFloat = 0 +// var g: CGFloat = 0 +// var b: CGFloat = 0 +// var a: CGFloat = 0 +// +// guard uiColor.getRed(&r, green: &g, blue: &b, alpha: &a) else { +// return nil +// } +// return (r, g, b, a) +// } +//} +// +// +//#Preview { +// UniView() +// .modelContainer(for: Unicycle.self) +//} diff --git a/Unicycle.swift b/Unicycle.swift index eccef11..482efae 100644 --- a/Unicycle.swift +++ b/Unicycle.swift @@ -1,13 +1,37 @@ import SwiftData import SwiftUI +@Model class Unicycle { + var createdAt: Date + var name: String + var red: CGFloat + var green: CGFloat + var blue: CGFloat + var alpha: CGFloat -@Model class Unicycle{ - var createdAt: Date = Date() - init(createdAt: Date) { + // Default values for all properties + init(createdAt: Date = Date(), name: String = "", red: CGFloat = CGFloat.random(in: 0...1), green: CGFloat = CGFloat.random(in: 0...1), blue: CGFloat = CGFloat.random(in: 0...1), alpha: CGFloat = 1) { self.createdAt = createdAt + self.name = name + self.red = red + self.green = green + self.blue = blue + self.alpha = alpha } - + var color: Color { + get { Color(red: red, green: green, blue: blue, + opacity: alpha) } + set { + UIColor(newValue).getRed( + &red, + green: &green, + blue: &blue, + alpha: &alpha + ) + } + } } + + diff --git a/UnicycleView.swift b/UnicycleView.swift index bf75dd6..6690316 100644 --- a/UnicycleView.swift +++ b/UnicycleView.swift @@ -1,32 +1,158 @@ -import SwiftData -import SwiftUI - -struct UnicycleView2: View { - var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) - } -} - -struct UnicycleView: View { - @Environment(\.modelContext) private var modelContext - @Query private var unis: [Unicycle] - - var body: some View { - Button("Add unicycle") { - modelContext.insert(Unicycle(createdAt: Date())) - } - List{ - ForEach(unis) { uni in - Text("Einrad von \(uni.createdAt.description)") - }.onDelete { - for index in $0 { - modelContext.delete(unis[index]) - } - } - } - } -} - -#Preview { - UnicycleView2() -} +//import SwiftData +//import SwiftUI +// +//struct UnicycleView2: View { +// var body: some View { +// Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) +// } +//} +// +//struct UnicycleView: View { +// @Environment(\.modelContext) private var modelContext +// @Query private var unis: [Unicycle] +// +// var body: some View { +// Button("Add unicycle") { +// modelContext.insert(Unicycle(createdAt: Date())) +// } +// List{ +// ForEach(unis) { uni in +// Text("Einrad von \(uni.createdAt.description)") +// }.onDelete { +// for index in $0 { +// modelContext.delete(unis[index]) +// } +// } +// } +// } +//} +// +// +// +// +//struct UniListView: View { +// @Environment(\.modelContext) private var modelContext +// @Query private var unis: [Unicycle] +// +// init(filter: String, sort: SortDescriptor) { +// _unis = Query(filter: #Predicate { +// filter.isEmpty || $0.name.contains(filter) +// }, sort: [sort]) +// } +// +// var body: some View { +// List { +// ForEach(unis) { u in +// NavigationLink { +// UniDetailView(uni: u) +// } label: { +// HStack { +// VStack(alignment: .leading) { +// Text(u.name) +// Text(u.createdAt.description) +// .font(.caption) +// } +// Spacer() +// ColorPicker("", selection: .constant(u.color)) +// .disabled(true) +// } +// } +// } +// .onDelete { +// for index in $0 { // [2, 3] +// modelContext.delete(unis[index]) +// } +// } +// } +// .navigationTitle("\(unis.count) Unicycles") +// } +//} +// +//struct UnicycleView3: View { +// @Environment(\.modelContext) private var modelContext +// +// @State private var isPresented = false +// @State private var sortOrder = SortDescriptor(\Unicycle.name) +// @State private var search = "" +// +// var body: some View { +// NavigationStack { +// UniListView(filter: search, sort: sortOrder) +// .searchable(text: $search) +// .toolbar { +// ToolbarItem(placement: .topBarLeading) { +// EditButton() +// } +// ToolbarItem(placement: .topBarTrailing) { +// HStack { +// Button("Add", systemImage: "plus") { isPresented = true } +// picker +// } +// } +// } +// .sheet(isPresented: $isPresented) { +// UniDetailView(uni: Unicycle()) +// } +// Button("Save") { +// try? modelContext.save() +// } +// } +// } +// +// var picker: some View { +// Menu("Sort", systemImage: "arrow.up.arrow.down") { +// Picker("Sort", selection: $sortOrder) { +// Text("Name") +// .tag(SortDescriptor(\Unicycle.name)) +// Text("Date") +// .tag(SortDescriptor(\Unicycle.createdAt, order: .reverse)) +// } +// .pickerStyle(.inline) +// } +// } +//} +// +//struct UniDetailView2: View { +// @Environment(\.modelContext) private var modelContext +// @Bindable var uni: Unicycle +// @Environment(\.dismiss) private var dismiss +// +// var body: some View { +// Form { +// DefaultTextField("Enter a name", $uni.name) +// ColorPicker("Color", selection: $uni.color) +// Button("Save") { +// modelContext.insert(uni) +// dismiss() +// } +// } +// } +//} +// +//struct DefaultTextField: View { +// @FocusState private var isFocused: Bool +// private var placeholder: String +// private var text: Binding +// +// init(_ placeholder: String = "", _ text: Binding) { +// self.placeholder = placeholder +// self.text = text +// } +// +// var body: some View { +// TextField(placeholder, text: text) +// .focused($isFocused) +// .onAppear { isFocused = true } +// } +//} +// +//#Preview { +// UnicycleView() +// .modelContainer(for: Unicycle.self) +//} +// +// +// +//#Preview { +// UnicycleView() +//} diff --git a/WebAppView.swift b/WebAppView.swift new file mode 100644 index 0000000..13c97df --- /dev/null +++ b/WebAppView.swift @@ -0,0 +1,51 @@ +// +// WebView.swift +// TheSwiftWeek +// +// Created by Ingo Rohlf on 23.10.25. +// + +import SwiftUI + +import WebKit + + + +struct WebAppView: View { +// @State private var page = WebPage() + + var body: some View { + + if let url = URL(string: "https://git.irohlf.de") { + + if #available(iOS 27.0, *) { + Text("WebView für iOS 26+") + WebView(url: url) + + } else { + Text("please update to iOS 26.0 or later") + WebOldView(url: URL(string: "https://ai.irohlf.de")!) + } + + } + + } +} + +struct WebOldView: UIViewRepresentable { + let url: URL + typealias UIViewType = WKWebView + func makeUIView(context: Context) -> WKWebView { + .init() + } + func updateUIView(_ uiView: WKWebView, context: Context) { + uiView.load(URLRequest(url: url)) + } + +} + + + +#Preview { + WebAppView() +}