Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 971
shahin ali agharia Avatar asked Dec 20 '16 09:12

shahin ali agharia


2 Answers

You need to use base64EncodedString() function of NSData.

let base64String = plainData?.base64EncodedString()

This works with Swift 3.0

like image 52
Gurdev Singh Avatar answered Nov 06 '22 21:11

Gurdev Singh


Actually with update of swift version it gives an error. We can do something like:

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

It solved my problem.

like image 44
shahin ali agharia Avatar answered Nov 06 '22 21:11

shahin ali agharia