diff --git a/Sources/Scout/ExplorerXML/ExplorerXML+Add.swift b/Sources/Scout/ExplorerXML/ExplorerXML+Add.swift index d8282ac..3ffad59 100644 --- a/Sources/Scout/ExplorerXML/ExplorerXML+Add.swift +++ b/Sources/Scout/ExplorerXML/ExplorerXML+Add.swift @@ -14,12 +14,38 @@ extension ExplorerXML { try _add(value: .explorerValue(value), at: Slice(path)) } + /// Add the given `AEXMLElement` value rather than an `ExplorerValue` + public mutating func add(_ element: Element, at path: Path) throws { + if referenceIsShared() { self = copy() } + try _add(value: .explorerXML(ExplorerXML(element: element)), at: Slice(path)) + } + + /// Add the given `ExplorerXML` value rather than an `ExplorerValue` + public mutating func add(_ explorer: ExplorerXML, at path: Path) throws { + if referenceIsShared() { self = copy() } + try _add(value: .explorerXML(explorer), at: Slice(path)) + } + public func adding(_ value: ExplorerValue, at path: Path) throws -> ExplorerXML { var copy = self.copy() try copy.add(value, at: path) return copy } + /// Add the given `AEXMLElement` value rather than an `ExplorerValue` + public func adding(_ element: Element, at path: Path) throws -> ExplorerXML { + var copy = self.copy() + try copy.add(element, at: path) + return copy + } + + /// Add the given `ExplorerXML` value rather than an `ExplorerValue` + public func adding(_ explorerXML: ExplorerXML, at path: Path) throws -> ExplorerXML { + var copy = self.copy() + try copy.add(explorerXML, at: path) + return copy + } + // MARK: General function /// Return the value if it should be added to the parent diff --git a/Sources/Scout/ExplorerXML/ExplorerXML+Set.swift b/Sources/Scout/ExplorerXML/ExplorerXML+Set.swift index c1efab4..5417673 100644 --- a/Sources/Scout/ExplorerXML/ExplorerXML+Set.swift +++ b/Sources/Scout/ExplorerXML/ExplorerXML+Set.swift @@ -16,21 +16,33 @@ extension ExplorerXML { try _set(path: Slice(path), to: .explorerValue(newValue)) } + /// Set the path to the given `AEXMLElement` value rather than an `ExplorerValue` + public mutating func set(_ path: Path, to element: Element) throws { + try _set(path: Slice(path), to: .explorerXML(ExplorerXML(element: element))) + } + + /// Set the path to the given `ExplorerXML` value rather than an `ExplorerValue` + public mutating func set(_ path: Path, to explorer: ExplorerXML) throws { + try _set(path: Slice(path), to: .explorerXML(explorer)) + } + public func setting(_ path: Path, to newValue: ExplorerValue) throws -> ExplorerXML { var modified = copy() try modified.set(path, to: newValue) return modified } - /// Set the path to the given AEXMLElement rather than an `ExplorerValue` - public mutating func set(_ path: Path, to newElement: Element) throws { - try _set(path: Slice(path), to: .xmlElement(newElement)) + /// Set the path to the given `AEXMLElement` value rather than an `ExplorerValue` + public func setting(_ path: Path, to element: Element) throws -> ExplorerXML { + var modified = copy() + try modified.set(path, to: element) + return modified } - /// Set the path to the given AEXMLElement rather than an `ExplorerValue` - public func setting(_ path: Path, to newElement: Element) throws -> ExplorerXML { + /// Set the path to the given `ExplorerXML` value rather than an `ExplorerValue` + public func setting(_ path: Path, to explorer: ExplorerXML) throws -> ExplorerXML { var modified = copy() - try modified.set(path, to: newElement) + try modified.set(path, to: explorer) return modified } diff --git a/Sources/Scout/ExplorerXML/ExplorerXML.swift b/Sources/Scout/ExplorerXML/ExplorerXML.swift index d27442c..8bc50a7 100644 --- a/Sources/Scout/ExplorerXML/ExplorerXML.swift +++ b/Sources/Scout/ExplorerXML/ExplorerXML.swift @@ -31,7 +31,7 @@ public struct ExplorerXML: PathExplorer { public var int: Int? { element.int } public var double: Double? { element.double } - @available(*, deprecated) + @available(*, deprecated, renamed: "double") public var real: Double? { element.double } /// Always `nil` on XML @@ -259,7 +259,7 @@ extension ExplorerXML { func set(value: ValueSetter) { switch value { case .explorerValue(let value): set(newValue: value) - case .xmlElement(let element): set(newElement: element) + case .explorerXML(let explorer): set(newElement: explorer.element) } } @@ -306,7 +306,7 @@ extension ExplorerXML { /// Wrapper to more easily handle setting an ExplorerValue or Element enum ValueSetter { case explorerValue(ExplorerValue) - case xmlElement(Element) + case explorerXML(ExplorerXML) } } diff --git a/Sources/Scout/Models/PathExplorer/CodablePathExplorer.swift b/Sources/Scout/Models/PathExplorer/CodablePathExplorer.swift index 9061e9b..e777845 100644 --- a/Sources/Scout/Models/PathExplorer/CodablePathExplorer.swift +++ b/Sources/Scout/Models/PathExplorer/CodablePathExplorer.swift @@ -15,7 +15,9 @@ public struct CodablePathExplorer: PathExplorer { public var string: String? { value.string } public var bool: Bool? { value.bool } public var int: Int? { value.int } + @available(*, deprecated, renamed: "double") public var real: Double? { value.real } + public var double: Double? { value.real } public var data: Data? { value.data } public func array(of type: T.Type) throws -> [T] where T: ExplorerValueCreatable { try value.array(of: type) } public func dictionary(of type: T.Type) throws -> [String: T] where T: ExplorerValueCreatable { try value.dictionary(of: type) } diff --git a/Sources/Scout/Models/PathExplorer/PathExplorer.swift b/Sources/Scout/Models/PathExplorer/PathExplorer.swift index ee9d84e..01a3de2 100644 --- a/Sources/Scout/Models/PathExplorer/PathExplorer.swift +++ b/Sources/Scout/Models/PathExplorer/PathExplorer.swift @@ -31,6 +31,9 @@ where /// Non `nil` if the key is of the `Double` type var real: Double? { get } + /// Non `nil` if the key is of the `Double` type + var double: Double? { get } + /// Non `nil` if the key is of the `Data` type var data: Data? { get }