Skip to content

Instantly share code, notes, and snippets.

@dedeexe
Last active November 25, 2015 17:33
Show Gist options
  • Save dedeexe/0fd85a59deabe5793a15 to your computer and use it in GitHub Desktop.
Save dedeexe/0fd85a59deabe5793a15 to your computer and use it in GitHub Desktop.
Convert String to base64 String
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