/Waaatcher

File Watcher Wrapper for macOS

Primary LanguageSwiftMIT LicenseMIT

Waaatcher

Build Status Cocoapods Cocoapods platforms Swift Version

File Watcher Wrapper for macOS

Demo

Demo

FileSystemEvent

FileSystemEvent API

How to use

Start

let watcher = Waaatcher(paths: [path1, path2, path3])

// ...
watcher.watcherEventCallback = { events in
    print("Events: \(events)")
}

watcher.start()

Stop

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.

Reactive Extension

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)

References

  1. Using the FSEventsFramework
  2. Apple FSEvents