Created
June 19, 2019 03:17
-
-
Save yllan/1595acebf298ef7e97f3660365f155aa to your computer and use it in GitHub Desktop.
Encode MKPolyline to Data
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
func encode(line: MKPolyline) -> Data { | |
return Data(buffer: UnsafeBufferPointer(start: line.points(), count: line.pointCount)) | |
} | |
func decode(data: Data) -> MKPolyline { | |
let buf = UnsafeMutableBufferPointer<MKMapPoint>.allocate(capacity: data.count / MemoryLayout<MKMapPoint>.size) | |
data.copyBytes(to: buf) | |
return MKPolyline(points: buf.baseAddress!, count: buf.count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
跪了