1
コレクションビューにデータを入力するためにドキュメントディレクトリからイメージを取得しようとしましたが、try
ブロックがerror
を返しますが、エラーの内容や原因がわかりません。エラーを投げてみてください、なぜですか?
func refreshCollectionView() {
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let url = NSURL(fileURLWithPath: path)
let filePath = url.appendingPathComponent(imagesDirectoryPath)?.path
let fileManager = FileManager.default
if fileManager.fileExists(atPath: filePath!) {
print("FILE AVAILABLE")
do {
titles = try FileManager.default.contentsOfDirectory(atPath: imagesDirectoryPath)
print(titles.count)
for image in titles {
let data = FileManager.default.contents(atPath: imagesDirectoryPath + "/\(image)")
let image = UIImage(data: data!)
myImages.append(image!)
}
self.collectionView?.reloadData()
}
catch {
print("Error")
}
}
else {
print("FILE NOT AVAILABLE")
}
}
ラインprint(titles.count)
が実行されることはありませんし、エラーがキャッチされたが、エラーは何ですか?