How to monitor a folder for new files in swift?

前端 未结 10 1995
既然无缘
既然无缘 2020-12-23 17:17

How would I monitor a folder for new files in swift, without polling (which is very inefficient)? I\'ve heard of APIs such as kqueue and FSEvents - but I\'m not sure it\'s p

10条回答
  •  囚心锁ツ
    2020-12-23 17:52

    The simplest solution is to use Apple's DirectoryMonitor.swift https://developer.apple.com/library/mac/samplecode/Lister/Listings/ListerKit_DirectoryMonitor_swift.html

    var dm = DirectoryMonitor(URL: AppDelegate.applicationDocumentsDirectory)
    dm.delegate = self
    dm.startMonitoring()
    

提交回复
热议问题