TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jul 2016 |
SPMSupports SPM | ✗ |
Maintained by David Chavez.
DirectoryObserver
is a microlibrary for monitoring directory changes using GCD.
Get an instance of DirectoryObserver
by either instantiation or using the extension method on NSURL
:
DirectoryObserver(pathToWatch: NSURL, completion: () -> Void) -> DirectoryObserver
NSURL.setupObserver() -> DirectoryObserver
The completion closure will be called when changes are detected and have completed.
let fileManager = NSFileManager.defaultManager()
let directory = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
directoryWatcher = DirectoryObserver(pathToWatch: directory) {
print("Directory contents have changed")
}
/*
// added method on `NSURL` directly -- equivalent to example above
directoryWatcher = directory.setupObserver() {
print("Directory contents have changed")
}
*/
You may then use the startObserving()
or stopObserving()
methods to stop/start/resume observing.
DirectoryObserver
is a Swift port of MHWDirectoryWatcher