File Watcher Wrapper for macOS
let watcher = Waaatcher(paths: [path1, path2, path3])
// ...
watcher.watcherEventCallback = { events in
print("Events: \(events)")
}
watcher.start()
watcher.stop()
// or watcher = nil
Each event is a structure which contains three parts as below
struct WaaaFSEvent {
let path: String
let flags: WaaaFSEventFlags
let ID: FSEventStreamEventId
}
Also, WaaaFSEventFlags
is defined as the wrapper of unreadable FSEventStreamEventFlags
.
v1.0 extend Waaatcher with Reactive extension. Dead-simple API as below, Not like the Waaatcher native callback with event array parameter, rx extension emit each single event.
fileprivate let bag = DisposeBag()
// ...
let watcher = Waaatcher(paths: [path])
watcher?.rx.FSEventObservable.subscribe(onNext: { [weak self] in
self?.output("Event: \($0)")
}).disposed(by: bag)