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)