Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pronebird/70aa9da5a42acd1bf8b0777f49997b77 to your computer and use it in GitHub Desktop.
Save pronebird/70aa9da5a42acd1bf8b0777f49997b77 to your computer and use it in GitHub Desktop.
Encode CLLocationCoordinate2D with Codable in Swift 4
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