Skip to content

Commit

Permalink
Encode URLs to URL directly
Browse files Browse the repository at this point in the history
  • Loading branch information
gering committed Dec 6, 2021
1 parent 087a478 commit d40570e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Sources/DictionaryCoding/DictionaryEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d40570e

Please sign in to comment.