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:
@@ -172,3 +172,17 @@ extension NSRange : CustomPlaygroundQuickLookable {
|
||||
}
|
||||
}
|
||||
|
||||
extension NSRange : Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
var container = try decoder.unkeyedContainer()
|
||||
let location = try container.decode(Int.self)
|
||||
let length = try container.decode(Int.self)
|
||||
self.init(location: location, length: length)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.unkeyedContainer()
|
||||
try container.encode(self.location)
|
||||
try container.encode(self.length)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user