Swift 3 & 4 Save Image to App Documents Folder

    // Create a URL
    let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
    let imageURL = documentsURL?.appendingPathComponent("\(String(describing: title)).png")


    // save image to URL
    if thumbnailData == nil {
        print("No Picture")
    } else {
        let notificationImage = UIImage(data: thumbnailData as! Data) // or wherever you have your UIImage
        do {
            try UIImagePNGRepresentation(notificationImage!)?.write(to: notificationImageURL!)                    
        } catch {
            print("Couldnt save image" )
        }
    }