Skip to content

Instantly share code, notes, and snippets.

@Burgestrand
Created December 20, 2017 09:38
Show Gist options
  • Save Burgestrand/c64f6bd43f51b1f792014b201a6aeba4 to your computer and use it in GitHub Desktop.
Save Burgestrand/c64f6bd43f51b1f792014b201a6aeba4 to your computer and use it in GitHub Desktop.
import Foundation
import CoreGraphics
var points: [CGPoint] = []
points.append(.zero)
points.append(CGPoint(x: 10, y: 20))
let encoder = JSONEncoder()
let encoded = try! encoder.encode(points)
let json = String(data: encoded, encoding: .utf8)!
debugPrint(json)
let decoder = JSONDecoder()
let data = json.data(using: .utf8)!
let decoded = try! decoder.decode([CGPoint].self, from: data)
debugPrint(decoded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment