大家好,我想从文档中提取所有图像并将其附加到单元格中。
我创建了此功能来将图像保存在didSelectItemAt
func saveImage(image: UIImage, imageName: String) {
let path = "yourProjectImages"
let document = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent(path, isDirectory: true)
let imageUrl = document!.appendingPathComponent("\(imageName).jpg", isDirectory: true)
do {
try UIImagePNGRepresentation(image)?.write(to: imageUrl, options: .atomic)
} catch {
print(error.localizedDescription)
}
}
我使用了它,就像我在didSelectItemAt中所说的那样
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedImage = images[indexPath.item]
saveImage(image: selectedImage, imageName: "\(selectedImage)")
}
it seems to add picture immediately in document after clicking on the picture
但是如何在我的rootController的HomeFeed中获取它们呢?
这些显示的照片是相册,我使用“照片”框架从相册中获取多张照片。