Developing a FileSystemWatcher for OS X by using FSEvents with Swift 2.0

Beecome Digital

When Swift was announced at WWDC 2014, I was very disappointed to not be able to use some of powerful C APIs such as FSEvents, to write applications in pure Swift language.

A lot of C APIs needs a C function pointer to pass a callback function when you use the API. From Swift 1.0 to Swift 1.2, it was not possible to use C function pointer in pure Swift language.

It was possible to use FSEvents by wrapping it in an Objective-C class, and by calling this class in Swift by using the bridging features offered by the language, but it was not what I attempted to accomplish.

But things change and at WWDC 2015, Apple announced the possibility to use C function pointers with Swift 2.0.

Today I’m very pleased to give you a sample code which is a good starting point to create your own FileSystemWatcher using…

View original post 30 more words