Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Created May 2, 2018 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanbehan/faeb4ef6d52b7e580f3f7b31b8062552 to your computer and use it in GitHub Desktop.
Save seanbehan/faeb4ef6d52b7e580f3f7b31b8062552 to your computer and use it in GitHub Desktop.
Encode and decode strings in base64 in swift ios
extension String {
func fromBase64() -> String? {
guard let data = Data(base64Encoded: self) else {
return nil
}
return String(data: data, encoding: .utf8)
}
func toBase64() -> String {
return Data(self.utf8).base64EncodedString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment