Convert UIImage to Base64 in Swift

Get Base64 string From UIImage

 func convertImageToBase64(_ image: UIImage) -> String {
        let imageData:NSData = UIImageJPEGRepresentation(image, 0.4)! as NSData
        let strBase64 = imageData.base64EncodedString(options: .lineLength64Characters)
        return strBase64
 }

Get UIImage from base64 string

func convertBase64ToImage(_ str: String) -> UIImage {
        let dataDecoded : Data = Data(base64Encoded: str, options: .ignoreUnknownCharacters)!
        let decodedimage = UIImage(data: dataDecoded)
        return decodedimage!
}