我有一个项目正在创建并保存本地PDF文件到DocumentDirectoy
。我已阅读here以了解如何查看DocumentDirectory
并为其筛选PDF
文件。我希望DocumentDirectory
文件可以在UITableView
中查看。我知道我必须有一个array
。我看到here这样做,但无法弄清楚如何将DocumentDirectory
放入Swift 2.0中的数组中以显示在我的UITableView
中。我的PDF文件正在保存并可在我的UIWebView
中查看。用于Xcode 7和Swift 2.0的UITableView Array中的DocumentsDirectory
我看我的DocumentDirectory
PDF的代码是:
func itemsInDirectory() {
// We need just to get the documents folder url
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
// now lets get the directory contents (including folders)
do {
let directoryContents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions())
print("Items: \(directoryContents)")
} catch let error as NSError {
print(error.localizedDescription)
}
// if you want to filter the directory contents you can do like this:
do {
let directoryUrls = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions())
print(directoryUrls)
let PDFFiles = directoryUrls.filter(){ $0.pathExtension == "pdf" }.map{ $0.lastPathComponent }
print("PDF FILES:\n" + PDFFiles.description)
} catch let error as NSError {
print(error.localizedDescription)
}
}
它打印出他们当我运行它。有人可以帮助我将DocumentDirectory
转换为数组以查看我的UITableView
?谢谢。