I’ve been looking around and it looks like VDKQueue is a more modern version of UKKQueue, but I’m having trouble implementing it (I’m not great at Cocoa yet). I have this so far but I’m at a bit of a loss on what else I need (or if this is even right):
VDKQueue *kqueue = [[VDKQueue alloc] init];
[kqueue addPath:path notifyingAbout:VDKQueueNotifyAboutWrite];
[kqueue setDelegate:self];
This answer seems to nicely outline how to set it up, I just don't really understand it. Now that I have VDKQueue initialized, how to I set what happens when the file is modified?
Cocoa Monitor a file for modifications
From the other answer:
Implementation was pretty straightforward:
- let your controller be the
VDKQueueDelegate
; (I added<VDKQueueDelegate>
to my AppDelegate.h)- declare a
VDKQueue*
ivar / property; (Is thisVDKQueue *kqueue = [[VDKQueue alloc] init];
?)- setup delegate method
VDKQueue:receivedNotification:forPath:
; (How do I do this?)- init the queue and set its delegate to the controller itself; (is this this
[kqueue setDelegate:self]
;?)- add resources to watch with
addPath:notifyingAbout:
. (Added this line[kqueue addPath:path notifyingAbout:VDKQueueNotifyAboutWrite];
)Then just do your business in the delegate method.
Possibly the delegate method from the code?
//
// Or, instead of subscribing to notifications, you can specify a delegate and implement this method to respond to kQueue events.
// Note the required statement! For speed, this class does not check to make sure the delegate implements this method. (When I say "required" I mean it!)
//
@class VDKQueue;
@protocol VDKQueueDelegate <NSObject>
@required
-(void) VDKQueue:(VDKQueue *)queue receivedNotification:(NSString*)noteName forPath:(NSString*)fpath;
@end