So i'm downloading an image using DownloadTask , and than save the image in the Cache Directory with name for my own uses :
let fileManager = NSFileManager.defaultManager()
let documents = fileManager.URLsForDirectory(NSSearchPathDirectory.CachesDirectory, inDomains: .UserDomainMask).first as NSURL
let fileURL = documents.URLByAppendingPathComponent("\((id)).png")
var error: NSError?
if !fileManager.moveItemAtURL(location, toURL: fileURL, error: &error) {
//already exist?
}
If i println the fileURL it wll give me : file:///var/mobile/Containers/Data/Application/A5F342C0-DFFA-49C4-92C1-3A0326A8C2D2/Library/Caches/1806.png
And than i try load it ->
imagechecker.image = UIImage(contentsOfFile:"file:///var/mobile/Containers/Data/Application/A5F342C0-DFFA-49C4-92C1-3A0326A8C2D2/Library/Caches/1806.png")
It doesnt work.. I saw that someone said that the serial part might change with each build , so i tried this as well :
let documents = fileManager.URLsForDirectory(NSSearchPathDirectory.CachesDirectory, inDomains: .UserDomainMask).first as NSURL
let fileURL = documents.URLByAppendingPathComponent("1797.png")
imagechecker.image = UIImage(contentsOfFile: fileURL.absoluteString!)
Doesnt work as well, any thoughts?