I am trying to update the content of an image from xcassets (through code, since I should download the new image) I need this so I can try to dynamically update the splash screen image and home page image (both are referenced from the same file in xcassets). This is because splash screen can only reference a locally present image.
I tried the following, but it does not work. Any help is appreciated.
var urlString = Bundle.main.resourcePath
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let filename = URL(fileURLWithPath: urlString!)
let fileURL = filename.appendingPathComponent("image_splashscreen@3x.png")
if let pngImageData = image.pngData() {
try! pngImageData.write(to: fileURL, options: .atomic)
And also:
var documentsUrlw: URL {
return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
}
let fileName = "image_splashscreen@3x"
let fileURL = documentsUrl.appendingPathComponent(fileName)
if let imageData = image.jpegData(compressionQuality: 1.0) {
try? imageData.write(to: fileURL, options: .atomic)
return fileName // ----> Save fileName
}
In both cases the image doesn't update.