From 233814dc48313da5eb4acc499727701e1b95c853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Julian-Steffen=20M=C3=BCller?= Date: Thu, 20 May 2021 14:52:58 +0200 Subject: [PATCH] Removed Codeable-Any extzension --- Zockerhoehle.xcodeproj/project.pbxproj | 4 - Zockerhoehle/Utils/CodableExtensionAny.swift | 111 ------------------- 2 files changed, 115 deletions(-) delete mode 100644 Zockerhoehle/Utils/CodableExtensionAny.swift diff --git a/Zockerhoehle.xcodeproj/project.pbxproj b/Zockerhoehle.xcodeproj/project.pbxproj index 1df4a31..b9cc5c1 100644 --- a/Zockerhoehle.xcodeproj/project.pbxproj +++ b/Zockerhoehle.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ B90E03EB238557D900E79643 /* LibraryImport.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90E03EA238557D900E79643 /* LibraryImport.swift */; }; - B926F14721502D53004D36B7 /* CodableExtensionAny.swift in Sources */ = {isa = PBXBuildFile; fileRef = B926F14621502D53004D36B7 /* CodableExtensionAny.swift */; }; B93C1B9D21496BFD0014FD6E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B93C1B9C21496BFD0014FD6E /* AppDelegate.swift */; }; B93C1BA421496BFE0014FD6E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B93C1BA321496BFE0014FD6E /* Assets.xcassets */; }; B93D60CE22D88F5700DD390F /* AccessoryDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B93D60CD22D88F5700DD390F /* AccessoryDetailView.swift */; }; @@ -76,7 +75,6 @@ /* Begin PBXFileReference section */ B90E03EA238557D900E79643 /* LibraryImport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryImport.swift; sourceTree = ""; }; - B926F14621502D53004D36B7 /* CodableExtensionAny.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableExtensionAny.swift; sourceTree = ""; }; B93C1B9921496BFD0014FD6E /* Zockerhoehle.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Zockerhoehle.app; sourceTree = BUILT_PRODUCTS_DIR; }; B93C1B9C21496BFD0014FD6E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; B93C1BA321496BFE0014FD6E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -175,7 +173,6 @@ B926F13A214AF21B004D36B7 /* Utils */ = { isa = PBXGroup; children = ( - B926F14621502D53004D36B7 /* CodableExtensionAny.swift */, B94112DD233A37DD00159AE4 /* DateConversion.swift */, B9EC09812383F94B004BC9AB /* LibraryExport.swift */, B90E03EA238557D900E79643 /* LibraryImport.swift */, @@ -413,7 +410,6 @@ B9EC09822383F94B004BC9AB /* LibraryExport.swift in Sources */, B94CB50022D1352F0029BFAD /* Accessory+CoreDataProperties.swift in Sources */, B9E2A07B233B6A8F00EAEB14 /* GameSeriesEditView.swift in Sources */, - B926F14721502D53004D36B7 /* CodableExtensionAny.swift in Sources */, B94CB50422D1352F0029BFAD /* Game+CoreDataProperties.swift in Sources */, B9BCCEBB2653CA8E005F46D6 /* SwiftUIBindingExtension.swift in Sources */, B98A736022C1738800FB3410 /* CDManager.swift in Sources */, diff --git a/Zockerhoehle/Utils/CodableExtensionAny.swift b/Zockerhoehle/Utils/CodableExtensionAny.swift deleted file mode 100644 index 0270f59..0000000 --- a/Zockerhoehle/Utils/CodableExtensionAny.swift +++ /dev/null @@ -1,111 +0,0 @@ -// -// Ext.swift -// Zockerhoehle -// -// Created by Julian-Steffen Müller on 17.09.18. -// Copyright © 2018 Julian-Steffen Müller. All rights reserved. -// - -import Foundation - -// Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a - -struct JSONCodingKeys: CodingKey { - var stringValue: String - - init?(stringValue: String) { - self.stringValue = stringValue - } - - var intValue: Int? - - init?(intValue: Int) { - self.init(stringValue: "\(intValue)") - self.intValue = intValue - } -} - - -extension KeyedDecodingContainer { - - func decode(_ type: Dictionary.Type, forKey key: K) throws -> Dictionary { - let container = try self.nestedContainer(keyedBy: JSONCodingKeys.self, forKey: key) - return try container.decode(type) - } - - func decodeIfPresent(_ type: Dictionary.Type, forKey key: K) throws -> Dictionary? { - guard contains(key) else { - return nil - } - guard try decodeNil(forKey: key) == false else { - return nil - } - return try decode(type, forKey: key) - } - - func decode(_ type: Array.Type, forKey key: K) throws -> Array { - var container = try self.nestedUnkeyedContainer(forKey: key) - return try container.decode(type) - } - - func decodeIfPresent(_ type: Array.Type, forKey key: K) throws -> Array? { - guard contains(key) else { - return nil - } - guard try decodeNil(forKey: key) == false else { - return nil - } - return try decode(type, forKey: key) - } - - func decode(_ type: Dictionary.Type) throws -> Dictionary { - var dictionary = Dictionary() - - for key in allKeys { - if let boolValue = try? decode(Bool.self, forKey: key) { - dictionary[key.stringValue] = boolValue - } else if let stringValue = try? decode(String.self, forKey: key) { - dictionary[key.stringValue] = stringValue - } else if let intValue = try? decode(Int.self, forKey: key) { - dictionary[key.stringValue] = intValue - } else if let doubleValue = try? decode(Double.self, forKey: key) { - dictionary[key.stringValue] = doubleValue - } else if let nestedDictionary = try? decode(Dictionary.self, forKey: key) { - dictionary[key.stringValue] = nestedDictionary - } else if let nestedArray = try? decode(Array.self, forKey: key) { - dictionary[key.stringValue] = nestedArray - } - } - return dictionary - } -} - -extension UnkeyedDecodingContainer { - - mutating func decode(_ type: Array.Type) throws -> Array { - var array: [Any] = [] - while isAtEnd == false { - // See if the current value in the JSON array is `null` first and prevent infite recursion with nested arrays. - if try decodeNil() { - continue - } else if let value = try? decode(Bool.self) { - array.append(value) - } else if let value = try? decode(Double.self) { - array.append(value) - } else if let value = try? decode(String.self) { - array.append(value) - } else if let nestedDictionary = try? decode(Dictionary.self) { - array.append(nestedDictionary) - } else if let nestedArray = try? decode(Array.self) { - array.append(nestedArray) - } - } - return array - } - - mutating func decode(_ type: Dictionary.Type) throws -> Dictionary { - - let nestedContainer = try self.nestedContainer(keyedBy: JSONCodingKeys.self) - return try nestedContainer.decode(type) - } -}