Skip to content

Instantly share code, notes, and snippets.

@dkw5877
Created March 26, 2019 23:08
Show Gist options
  • Save dkw5877/0e249aa87a62a00fa05056dc62bd07df to your computer and use it in GitHub Desktop.
Save dkw5877/0e249aa87a62a00fa05056dc62bd07df to your computer and use it in GitHub Desktop.
Base 64 Key Encoding and Decoding in Swift
let dates = ["key_1":Date()]
let encoder = JSONEncoder()
encoder.dataEncodingStrategy = .base64
encoder.outputFormatting = [.sortedKeys, .prettyPrinted]
let encoded = try? encoder.encode(object)
print(String(data: encoded!, encoding: .utf8)!)
//output
{
"key_1" : 574821298.18860102
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment