我在Swift中遇到了问题。 我尝试加载存储在DocumentsDirectory中的图像,但它返回nil。UIImage返回零,但存在
下面是代码:
if NSFileManager.defaultManager().fileExistsAtPath(url!.path!) {
//show image
print("Image " + key + " exists")
if let image = UIImage(contentsOfFile: url!.path!){
return image
}
else {
print("error image")
return nil
}
}
我总是得到“错误图像”,但该文件存在。我不明白这个问题。
感谢,
亨利
不要使用强制解包,你打开门崩溃,如果你使用。 – Cristik
好的,但它仍然不加载图像.. – user3900157