Value of type "Data?" no base64EncodedStringWithOptions' element

Here I encode my string, but it gives the error mentioned above. I have done this:

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

This gives me an error in the second line of code. If someone can help!

+4
source share
2 answers

You need to use the function base64EncodedString()for NSData.

let base64String = plainData?.base64EncodedString()

This works with Swift 3.0

+6
source

Actually with updating the quick version this 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))

He solved my problem.

+4
source

Source: https://habr.com/ru/post/1664270/


All Articles