Created
July 4, 2017 09:46
-
-
Save pronebird/70aa9da5a42acd1bf8b0777f49997b77 to your computer and use it in GitHub Desktop.
Encode CLLocationCoordinate2D with Codable in Swift 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreLocation | |
extension CLLocationCoordinate2D: Codable { | |
public func encode(to encoder: Encoder) throws { | |
var container = encoder.unkeyedContainer() | |
try container.encode(longitude) | |
try container.encode(latitude) | |
} | |
public init(from decoder: Decoder) throws { | |
var container = try decoder.unkeyedContainer() | |
longitude = try container.decode(Double.self) | |
latitude = try container.decode(Double.self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment