My code, is very similar to yours, but the line is causing an EXC_BAD_ACCESS errpr:
let paths = unsafeBitCast(eventPaths, NSArray.self) as! [String]
Here's the full code for my subscribe implementation:
func subscribeToEvents()
{
var context:FSEventStreamContext = FSEventStreamContext()
context.info = nil;
context.version = 0;
context.retain = nil;
context.release = nil;
context.copyDescription = nil;
let fileSystemObserverCallback:FSEventStreamCallback = { (stream: ConstFSEventStreamRef, contextInfo: UnsafeMutablePointer<Void>, numEvents: Int, eventPaths: UnsafeMutablePointer<Void>, eventFlags: UnsafePointer<FSEventStreamEventFlags>, eventIds: UnsafePointer<FSEventStreamEventId>) in
print("File System Event Observed")
print(numEvents)
let paths = unsafeBitCast(eventPaths, NSArray.self) as! [String]
print( paths )
print("-------------")
}
let paths = [self.rootPath.path!];
let pathsToWatch = paths.map({$0 as NSString}) as [AnyObject];
self.stream = FSEventStreamCreate(nil, fileSystemObserverCallback, &context, pathsToWatch, FSEventStreamEventId(kFSEventStreamEventIdSinceNow), CFTimeInterval(1.0), FSEventStreamCreateFlags(kFSEventStreamCreateFlagWatchRoot) )
FSEventStreamScheduleWithRunLoop(self.stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)
FSEventStreamStart(self.stream)
print("Subscribed to FileStream Events");
}
The instance of this watcher class is retained by the constructing class as a member variable. Any thoughts? Maybe the version of swift changed this from working? I do notice that it says "UnsafeBitCast" is available on 10.11 and I'm trying to run this on 10.10.....
It does compile, maybe the version discrpency is causing a problem... was hoping to hold off. Maybe I'll look into GCD for this kind of watching in the mean time.