Last active
November 25, 2015 17:33
-
-
Save dedeexe/0fd85a59deabe5793a15 to your computer and use it in GitHub Desktop.
Convert String to base64 String
This file contains 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 { | |
var base64 : String? | |
{ | |
if let convertedData = self.dataUsingEncoding(NSUTF8StringEncoding) | |
{ | |
let convertedDataBase64 = convertedData.base64EncodedDataWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) | |
let stringBase64 = String(data: convertedDataBase64, encoding: NSUTF8StringEncoding) | |
return stringBase64 | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment