Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何扫描系统中的pdf文件并使用swift提醒pdf文件的数量?_Ios_Swift - Fatal编程技术网

Ios 如何扫描系统中的pdf文件并使用swift提醒pdf文件的数量?

Ios 如何扫描系统中的pdf文件并使用swift提醒pdf文件的数量?,ios,swift,Ios,Swift,我是新手。我不知道如何扫描系统中的pdf文件并使用swift通知pdf文件的数量。我找到了一个解决方案: var counter:Int=0 let alertController = UIAlertController() let file = NSFileManager.defaultManager() let enumer:NSDirectoryEnumerator = file.enumeratorAtPath(folderPath) while let element = enume

我是新手。我不知道如何扫描系统中的pdf文件并使用swift通知pdf文件的数量。

我找到了一个解决方案:

var counter:Int=0
let alertController = UIAlertController()
let file = NSFileManager.defaultManager()
let enumer:NSDirectoryEnumerator = file.enumeratorAtPath(folderPath)

while let element = enumer?.nextObject() as? String {
    if element.hasSuffix("pdf") { 
       counter++
    }
}
alertController(title: "Number of PDF Files", message:"\(counter)", preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(alertController, animated: true, completion: nil)

您无法在iOS中扫描系统中的文件。在文件夹路径中,我必须给出什么路径??在
中让枚举器:nsdirectorynumerator=file.EnumeratorPath(folderPath)
将folderPath替换为提供包含pdf文件的文件夹路径的字符串。检查文档。另外,如果我帮忙,请接受答案!:)