我有一個項目正在創建並保存本地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
?謝謝。