mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user