forked from bmdelacruz/FileSystemWatcher
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# FileSystemWatcher | ||
|
||
A bridge between Linux's C API [`inotify`](https://linux.die.net/man/7/inotify) and Swift. | ||
|
||
## Use cases | ||
|
||
For any async file system event monitoring, we gotcha. | ||
|
||
## Usage | ||
|
||
I made a [demonstration app](https://github.com/felix91gr/fswatcher-usage) of usage of this library. | ||
|
||
The most basic form of usage is as follows: | ||
|
||
```swift | ||
|
||
import FileSystemWatcher | ||
|
||
var eventCount : Int | ||
|
||
eventCount = 0 | ||
|
||
func printEvent(event: FileSystemEvent) { | ||
print("Hey! Something happened!!") | ||
// I'd love to use event.name, but I can't figure out yet how to read that from C's API | ||
// That'd be useful for debugging purposes. | ||
// But it's allright as long as you don't need to know the exact description of the ocurring events. | ||
eventCount += 1 | ||
} | ||
|
||
|
||
print("Starting!") | ||
|
||
let myWatcher = FileSystemWatcher() | ||
|
||
myWatcher.watch( | ||
paths: ["/tmp"], | ||
for: [FileSystemEventType.inAllEvents], | ||
thenInvoke: printEvent) | ||
|
||
|
||
myWatcher.start() | ||
|
||
readLine() | ||
|
||
myWatcher.stop() | ||
|
||
print("Total number of events: " + String(eventCount)) | ||
|
||
print("Finished!") | ||
|
||
``` |