Add Codable conformance to common Foundation types

Add conformances + unit tests for

* CGFloat
* AffineTransform
* Calendar
* CharacterSet
* DateComponents
* DateInterval
* Decimal
* IndexPath
* IndexSet
* Locale
* Measurement
* NSRange
* PersonNameComponents
* TimeZone
* URL
* UUID

along with some unit tests for each.
This commit is contained in:
Itai Ferber
2017-05-17 16:01:20 -07:00
parent f49808eb0b
commit 012ea9373b
22 changed files with 1135 additions and 113 deletions

View File

@@ -807,3 +807,19 @@ extension NSCharacterSet : _HasCustomAnyHashableRepresentation {
}
}
extension CharacterSet : Codable {
private enum CodingKeys : Int, CodingKey {
case bitmap
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let bitmap = try container.decode(Data.self, forKey: .bitmap)
self.init(bitmapRepresentation: bitmap)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.bitmapRepresentation, forKey: .bitmap)
}
}