I'm writing a small macOS app, where I want to be able to watch a folder for changes. It doesn't need to watch subfolder, I only want to receive a notification if a file is added to the folder or removed.
It looks like NSFileCoordinator
and/or NSFilePresenter
could be used to achieve this, but I was not able to understand how to use them to achieve this.
Ideally this can be solved without having to include a third party framework.
You can do this using NSFilePresenter. The observing class must conform to NSFilePresenter as shown below.
The presentedItemURL would point to the folder you want to observe. If there is a change in the folder presentedSubitemDidChangeAtURL get called. The code snipped below could give you an idea how it can work.
Best wishes.