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
How to Make Playground Execution Time Is as Fast as If We Run in iOS Application
Uitableviewcell Custom Class - Reload Cell Height After Change in Subview Height Constraint
How to Find the Index of a Tuple Element from an Tuple Array? iOS, Swift
Showing Hidden View Really Slow
Uitraitcollection Clarification
Adding a Target to a Button Programmatically Throws an Error "Unrecognized Selector Sent to Class"
Dynamic Uitablecellview Height
What Is the Simplest Way to Retrieve the Device Serial Number of an iOS Device Using Monotouch
Uibezierpath + Cashapelayer - Animate a Circle Filling Up
Avcapturevideopreviewlayer Add Overlays and Capture Photo in iOS
Swift - Update/Refresh Label That Displays Time
iOS Sound Not Playing in Swift
Firebase Authentication Error in Other Languages
Avaudioplayer Working on Simulator But Not on Real Device
If Let Doesn't Unwrap Optional Value for Mkannotation's Title Property
Swift: Nil Is Incompatible with Return Type String
Error "Call Can Throw, But Is Not Marked with 'Try' and the Error Is Not Handled"
Swift 4: Timer Crashing - Unrecognized Selector Sent to Instance