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 3358 views

I'm a 35 year old UIUC Computer Engineer building mobile apps, websites and hardware integrations with an interest in 3D printing, biotechnology and Arduinos.


View Comments

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