From 31678924bf3dfeb3ad51e1ed6924a7512e449bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Julian-Steffen=20M=C3=BCller?= Date: Thu, 27 May 2021 21:27:42 +0200 Subject: [PATCH] Removed extension vor optional bindings. Instead introduced binding for each variable in the views. Seems much cleaner. Maybe in some future xcode version that is implemented officially --- Zockerhoehle.xcodeproj/project.pbxproj | 4 ---- .../Utils/SwiftUIBindingExtension.swift | 17 ----------------- Zockerhoehle/Views/ConsoleEditView.swift | 16 ++++++++++++++-- Zockerhoehle/Views/GameSeriesEditView.swift | 8 +++++++- 4 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 Zockerhoehle/Utils/SwiftUIBindingExtension.swift diff --git a/Zockerhoehle.xcodeproj/project.pbxproj b/Zockerhoehle.xcodeproj/project.pbxproj index 67103f1..59cc7b5 100644 --- a/Zockerhoehle.xcodeproj/project.pbxproj +++ b/Zockerhoehle.xcodeproj/project.pbxproj @@ -33,7 +33,6 @@ B9A0550322F8C2740054D9A0 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9A0550222F8C2740054D9A0 /* MainView.swift */; }; B9A0550522F8CB400054D9A0 /* GameSeriesLibraryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9A0550422F8CB400054D9A0 /* GameSeriesLibraryView.swift */; }; B9BCCEB92653BDEA005F46D6 /* ICloudManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9BCCEB82653BDEA005F46D6 /* ICloudManager.swift */; }; - B9BCCEBB2653CA8E005F46D6 /* SwiftUIBindingExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9BCCEBA2653CA8E005F46D6 /* SwiftUIBindingExtension.swift */; }; B9BCF4CA2168ACB600ECBAAC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B9BCF4C92168ACB600ECBAAC /* LaunchScreen.storyboard */; }; B9E2A07B233B6A8F00EAEB14 /* GameSeriesEditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9E2A07A233B6A8F00EAEB14 /* GameSeriesEditView.swift */; }; B9E2A07E233B6E4F00EAEB14 /* ConsoleAllView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9E2A07C233B6E4F00EAEB14 /* ConsoleAllView.swift */; }; @@ -103,7 +102,6 @@ B9A0550222F8C2740054D9A0 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = ""; }; B9A0550422F8CB400054D9A0 /* GameSeriesLibraryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameSeriesLibraryView.swift; sourceTree = ""; }; B9BCCEB82653BDEA005F46D6 /* ICloudManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ICloudManager.swift; sourceTree = ""; }; - B9BCCEBA2653CA8E005F46D6 /* SwiftUIBindingExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIBindingExtension.swift; sourceTree = ""; }; B9BCF4C92168ACB600ECBAAC /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; B9E2A07A233B6A8F00EAEB14 /* GameSeriesEditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameSeriesEditView.swift; sourceTree = ""; }; B9E2A07C233B6E4F00EAEB14 /* ConsoleAllView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsoleAllView.swift; sourceTree = ""; }; @@ -171,7 +169,6 @@ B9EC09812383F94B004BC9AB /* LibraryExport.swift */, B90E03EA238557D900E79643 /* LibraryImport.swift */, B98CBBE2265045AC00B1B7AC /* URLExtension.swift */, - B9BCCEBA2653CA8E005F46D6 /* SwiftUIBindingExtension.swift */, ); path = Utils; sourceTree = ""; @@ -396,7 +393,6 @@ B94CB50022D1352F0029BFAD /* Accessory+CoreDataProperties.swift in Sources */, B9E2A07B233B6A8F00EAEB14 /* GameSeriesEditView.swift in Sources */, B94CB50422D1352F0029BFAD /* Game+CoreDataProperties.swift in Sources */, - B9BCCEBB2653CA8E005F46D6 /* SwiftUIBindingExtension.swift in Sources */, B98A736022C1738800FB3410 /* CDManager.swift in Sources */, B9E2A07E233B6E4F00EAEB14 /* ConsoleAllView.swift in Sources */, B9BCCEB92653BDEA005F46D6 /* ICloudManager.swift in Sources */, diff --git a/Zockerhoehle/Utils/SwiftUIBindingExtension.swift b/Zockerhoehle/Utils/SwiftUIBindingExtension.swift deleted file mode 100644 index a3c3387..0000000 --- a/Zockerhoehle/Utils/SwiftUIBindingExtension.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// SwiftUIBindingExtension.swift -// Zockerhoehle -// -// Created by Julian-Steffen Müller on 18.05.21. -// Copyright © 2021 Julian-Steffen Müller. All rights reserved. -// - -import Foundation -import SwiftUI - -func ??(lhs: Binding>, rhs: T) -> Binding { - Binding( - get: { lhs.wrappedValue ?? rhs }, - set: { lhs.wrappedValue = $0 } - ) -} diff --git a/Zockerhoehle/Views/ConsoleEditView.swift b/Zockerhoehle/Views/ConsoleEditView.swift index b0200d0..c29865f 100644 --- a/Zockerhoehle/Views/ConsoleEditView.swift +++ b/Zockerhoehle/Views/ConsoleEditView.swift @@ -11,14 +11,26 @@ import SwiftUI struct ConsoleEditView: View { @ObservedObject var console : Console + var consoleShortNameBinding: Binding { + Binding( + get: { self.console.shortName ?? "" }, + set: { self.console.shortName = $0 }) + } + + var consoleManufacturerBinding: Binding { + Binding( + get: { self.console.manufacturer ?? "" }, + set: { self.console.manufacturer = $0 }) + } + @State var isImportingLogo : Bool = false let defaultImage = UIImage() var body: some View { Form { TextField("Name der Konsole", text: $console.name) - TextField("Abkürzung", text: $console.shortName ?? "") - TextField("Hersteller", text: $console.manufacturer ?? "") + TextField("Abkürzung", text: consoleShortNameBinding) + TextField("Hersteller", text: consoleManufacturerBinding) DatePicker(selection: $console.releaseDate, in: ...Date(), displayedComponents: .date) { Text("Erscheinungsjahr") } diff --git a/Zockerhoehle/Views/GameSeriesEditView.swift b/Zockerhoehle/Views/GameSeriesEditView.swift index 4943c3c..2c6046d 100644 --- a/Zockerhoehle/Views/GameSeriesEditView.swift +++ b/Zockerhoehle/Views/GameSeriesEditView.swift @@ -11,11 +11,17 @@ import SwiftUI struct GameSeriesEditView: View { @ObservedObject var gameSeries : GameSeries + var seriesNameBinding: Binding { + Binding( + get: { self.gameSeries.name ?? "" }, + set: { self.gameSeries.name = $0 }) + } + @State var isImportingLogo : Bool = false var body: some View { Form { - TextField("Name der Konsole", text: $gameSeries.name ?? "") + TextField("Name der Konsole", text: seriesNameBinding) //TODO Image /*gameSeriesViewModel.cover.map {