Created
May 2, 2018 17:06
-
-
Save seanbehan/faeb4ef6d52b7e580f3f7b31b8062552 to your computer and use it in GitHub Desktop.
Encode and decode strings in base64 in swift ios
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
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