Swift 2 Cannot Invoke 'Fseventstreamcreate' with an Argument List of Type

Swift 2 Cannot invoke 'FSEventStreamCreate' with an argument list of type

You are using the wrong signature (UInt not Int):

typealias FSEventStreamCallback = @convention(c) (ConstFSEventStreamRef, UnsafeMutablePointer<Void>, Int, UnsafeMutablePointer<Void>, UnsafePointer<FSEventStreamEventFlags>, UnsafePointer<FSEventStreamEventId>) -> Void

This compiles fine:

init () {

let allocator: CFAllocator? = kCFAllocatorDefault

// Create FSEventStream and return valid FSEventStreamRef
// Alias FSEventStreamCallback - CFunction
typealias FSEventStreamCallback = @convention(c) (ConstFSEventStreamRef, UnsafeMutablePointer<Void>, Int, UnsafeMutablePointer<Void>, UnsafePointer<FSEventStreamEventFlags>, UnsafePointer<FSEventStreamEventId>) -> Void
let callback: FSEventStreamCallback = {
(streamRef, clientCallBackInfo, numEvents, eventPaths, eventFlags, eventIds) -> Void in
print ("changed")
// handle file event
}

let context: UnsafeMutablePointer<FSEventStreamContext> = nil
let pathsToWatch: CFArray = [NSHomeDirectory() + "/Dir"]
let sinceWhen: FSEventStreamEventId = UInt64(kFSEventStreamEventIdSinceNow)
let latency: CFTimeInterval = 1.0
let flags: FSEventStreamCreateFlags = UInt32(kFSEventStreamCreateFlagNone)

let eventStream = FSEventStreamCreate(
allocator,
callback,
context,
pathsToWatch,
sinceWhen,
latency,
flags
)

FSEventStreamScheduleWithRunLoop(eventStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)
FSEventStreamStart(eventStream)

}

Pass C function callback in Swift

With Swift 2.0 it is now possible to set up the callback in pure Swift! Please check http://oleb.net/blog/2015/06/c-callbacks-in-swift/ and Swift 2 Cannot invoke 'FSEventStreamCreate' with an argument list of type for inspiration :)

How to monitor file changes on network mapped drives?

You're correct, OS X mounts the network drives in /Volumes

The way to get file change updates is to use File System Events API. It is a C-based API where you would watch for all changes in specific directories (or even /).

You would create the stream with FSEventStreamCreate and starting it with FSEventStreamScheduleWithRunLoop

Be prepared to dig into the header-file as there is more documentation on it as in the Reference documentation

From what I can tell, Finder probably uses some internal API or the kernel queues which are more complex to setup than the higher-level API of FSEvents.h

There is a nice GUI to helping you see how the whole events come in. It's called fseventer by fernlightning (not yet Yosemite ready)



Related Topics



Leave a reply



Submit