Created
July 15, 2017 16:16
-
-
Save gavi/110bfdbff0f25c0d2e07490f5dc32ea7 to your computer and use it in GitHub Desktop.
JSON Encoding in Swift Basic Example
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 Foundation | |
struct Point:Codable{ | |
var x:Float | |
var y:Float | |
var moment:Date | |
} | |
let p=Point(x:10,y:10,moment:Date()) | |
let x=JSONEncoder() | |
x.dateEncodingStrategy = .iso8601 | |
let jsonData=try? x.encode(p) | |
if let data=jsonData{ | |
print(String(data:data , encoding: .utf8)!) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment