From c170b3271d063c05415dabca4f8e7ca883e4d3ad Mon Sep 17 00:00:00 2001 From: James Bean Date: Mon, 30 Sep 2019 20:10:11 -0400 Subject: [PATCH 1/3] Do a little cleanup of single keyed box passing around --- .../Decoder/XMLKeyedDecodingContainer.swift | 17 ++--- .../xcschemes/XMLCoder-Package.xcscheme | 68 +++++++++++++++++++ 2 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 XMLCoder.xcodeproj/xcshareddata/xcschemes/XMLCoder-Package.xcscheme diff --git a/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift b/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift index f16e09dd..d0d288a1 100644 --- a/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift +++ b/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift @@ -241,11 +241,11 @@ extension XMLKeyedDecodingContainer { let keyString = key.stringValue.isEmpty ? "value" : key.stringValue let value = keyedBox.elements[keyString] if !value.isEmpty { - return value.map { - if let singleKeyed = $0 as? SingleKeyedBox { + return value.map { box in + if let singleKeyed = box as? SingleKeyedBox { return singleKeyed.element } else { - return $0 + return box } } } else if let value = keyedBox.value { @@ -254,16 +254,7 @@ extension XMLKeyedDecodingContainer { return [] } } else { - #warning("TODO: just return keyedBox.elements[key.stringValue]") - return keyedBox.elements[key.stringValue].map { - if let singleKeyed = $0 as? SingleKeyedBox { - #warning("Don't get rid of key info just yet!") - // return singleKeyed.element - return singleKeyed - } else { - return $0 - } - } + return keyedBox.elements[key.stringValue] } } diff --git a/XMLCoder.xcodeproj/xcshareddata/xcschemes/XMLCoder-Package.xcscheme b/XMLCoder.xcodeproj/xcshareddata/xcschemes/XMLCoder-Package.xcscheme new file mode 100644 index 00000000..32ef6be3 --- /dev/null +++ b/XMLCoder.xcodeproj/xcshareddata/xcschemes/XMLCoder-Package.xcscheme @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + From 291bcaeccec4c8f5730b2fddbf2a752c4a4338e2 Mon Sep 17 00:00:00 2001 From: James Bean Date: Mon, 30 Sep 2019 22:41:20 -0400 Subject: [PATCH 2/3] Refactor XMLKeyedDecodingContainer.decodeConcrete elements massaging --- .../Decoder/XMLKeyedDecodingContainer.swift | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift b/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift index d0d288a1..dc7d7c5d 100644 --- a/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift +++ b/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift @@ -235,28 +235,19 @@ extension XMLKeyedDecodingContainer { ) } - let elements = container - .withShared { keyedBox -> [KeyedBox.Element] in - if ["value", ""].contains(key.stringValue) { - let keyString = key.stringValue.isEmpty ? "value" : key.stringValue - let value = keyedBox.elements[keyString] - if !value.isEmpty { - return value.map { box in - if let singleKeyed = box as? SingleKeyedBox { - return singleKeyed.element - } else { - return box - } - } - } else if let value = keyedBox.value { - return [value] - } else { - return [] - } - } else { - return keyedBox.elements[key.stringValue] - } + let elements = container.withShared { keyedBox -> [KeyedBox.Element] in + // Handle the coding key value intrinsic case + if ["value", ""].contains(key.stringValue) { + // For each boxed-up element we have, peer in to see if it is a `SingleKeyedBox`. + // A `SingleKeyedBox` bundles an `element` along with its `key` in order to defer + // its evaluation. This is used here in order to prevent the wiping away of + // `NullBox` elements prematurely which may be an empty `String` value in disguise. + // If we have a `SingledKeyedBox` here, extract its element. Otherwise, return the + // boxed-up element as-is. + return keyedBox.elements["value"].map { ($0 as? SingleKeyedBox)?.element ?? $0 } } + return keyedBox.elements[key.stringValue] + } let attributes = container.withShared { keyedBox in keyedBox.attributes[key.stringValue] From 6805ec6b4ce8ba8cf9f75f226816e521e7e7624b Mon Sep 17 00:00:00 2001 From: James Bean Date: Mon, 30 Sep 2019 22:45:55 -0400 Subject: [PATCH 3/3] Remove xcscheme junk --- .../xcschemes/XMLCoder-Package.xcscheme | 68 ------------------- 1 file changed, 68 deletions(-) delete mode 100644 XMLCoder.xcodeproj/xcshareddata/xcschemes/XMLCoder-Package.xcscheme diff --git a/XMLCoder.xcodeproj/xcshareddata/xcschemes/XMLCoder-Package.xcscheme b/XMLCoder.xcodeproj/xcshareddata/xcschemes/XMLCoder-Package.xcscheme deleted file mode 100644 index 32ef6be3..00000000 --- a/XMLCoder.xcodeproj/xcshareddata/xcschemes/XMLCoder-Package.xcscheme +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -