From d40570e750fe1d021e0190369f60b0950c6c6897 Mon Sep 17 00:00:00 2001 From: Robert Gering Date: Mon, 6 Dec 2021 14:52:21 +0100 Subject: [PATCH] Encode URLs to URL directly --- Sources/DictionaryCoding/DictionaryEncoder.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/DictionaryCoding/DictionaryEncoder.swift b/Sources/DictionaryCoding/DictionaryEncoder.swift index 8d3acc5..c9402b3 100644 --- a/Sources/DictionaryCoding/DictionaryEncoder.swift +++ b/Sources/DictionaryCoding/DictionaryEncoder.swift @@ -675,6 +675,7 @@ extension _DictionaryEncoder { fileprivate func box(_ value: UInt32) -> NSObject { return NSNumber(value: value) } fileprivate func box(_ value: UInt64) -> NSObject { return NSNumber(value: value) } fileprivate func box(_ value: String) -> NSObject { return NSString(string: value) } + fileprivate func box(_ value: URL) -> NSObject { return value as NSURL } fileprivate func box(_ float: Float) throws -> NSObject { guard !float.isInfinite && !float.isNaN else { @@ -827,8 +828,8 @@ extension _DictionaryEncoder { // Respect Data encoding strategy return try self.box((value as! Data)) } else if T.self == URL.self || T.self == NSURL.self { - // Encode URLs as single strings. - return self.box((value as! URL).absoluteString) + // Encode URLs as URLs. + return self.box((value as! URL)) } else if T.self == Decimal.self || T.self == NSDecimalNumber.self { // DictionarySerialization can natively handle NSDecimalNumber. return (value as! NSDecimalNumber)