Value of type 'Data?' has no member 'base64EncodedStringWithOptions'

shahin ali agharia picture shahin ali agharia · Dec 20, 2016 · Viewed 7.5k times · Source

Here I am encoding my string but it gives an error stated above. What I had done is:

let plainData = (password)?.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
let base64String = plainData.base64EncodedStringWithOptions(NSData.Base64EncodingOptions.init(rawValue: 0))

It gives me an error on the second line of code. If anyone can help!

Answer

Gurdev Singh picture Gurdev Singh · Dec 20, 2016

You need to use base64EncodedString() function of NSData.

let base64String = plainData?.base64EncodedString()

This works with Swift 3.0