Skip to content
TopicTracker
From HackerNewsView original
TranslationTranslation

Watching for File Changes on macOS

The article explains how to efficiently watch for file changes on macOS using Swift and the File System Events API, covering common pitfalls, practical code examples, and best practices for building file monitoring tools.

Background

This post explains how to use the `kqueue` API in Swift to monitor files for changes on macOS — a common need for developers building tools that auto-reload, sync, or react to edits. The author goes low-level (raw system calls), not high-level frameworks like `FSEvents` or `DispatchSource`. Key context: `kqueue` is a BSD kernel event mechanism; macOS supports it but Apple's modern `FileSystemEvents` framework is often preferred for simplicity. The post assumes familiarity with Swift, Unix file descriptors, and event-loop programming.