【发布时间】:2019-02-08 15:02:31
【问题描述】:
我正在尝试在我的文档目录中获取一组图像以显示在 UICollectionView 中我无法获取实际的图像数组。我花了一些时间尝试在谷歌上搜索,但大多数人似乎是从应用程序包中获取他们的图像。我需要我的图像来自文档。
这是我尝试使用的代码:
func getImageArray() {
let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
if let dirPath = paths.first
{
let imageURL = URL(fileURLWithPath: dirPath).appendingPathComponent("Images")
let image = UIImage(contentsOfFile: imageURL.path)
imageArray.append(image)
print(imageURL)
}
}
我对 swift 很陌生,所以答案可能很明显。有人可以指出我正确的方向或告诉我我做错了什么
【问题讨论】:
-
您尝试从指向字典的 URL 创建 UIImage。
-
好的,所以我需要一个指向我目录中每个图像的 URL 数组?对吗?
标签: arrays swift uicollectionview uiimage