iOS Swift

IOS8 Swift Base64 Conversion on Xcode 6.2


If you google search you will find many articles that have swift code to create Base64 encoded text. However Swift keeps changing and if you copy and paste the code, it just won’t run.

“my plain data”  >>>  “bXkgcGxhaW4gZGF0YQ==” (base64)

let plainString = "my plain data"

let plainData = (plainString as NSString).dataUsingEncoding(NSUTF8StringEncoding)
let base64String = plainData?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(0))

println(base64String!)

If this stop working, please leave a comment below.

openanalytics 4084 views

I'm a 36 year old UIUC Computer Engineer building easy to use tech to simplify our complicated lives with an interest in golang, rust, 3D printing, ESP32 and Arduinos.


View Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.