【发布时间】:2013-01-12 21:27:48
【问题描述】:
我一直在环顾四周,看起来 VDKQueue 是 UKKQueue 的更现代版本,但我在实现它时遇到了麻烦(我还不擅长 Cocoa)。 到目前为止我有这个,但我对我还需要什么(或者如果这甚至是正确的)有点茫然:
VDKQueue *kqueue = [[VDKQueue alloc] init];
[kqueue addPath:path notifyingAbout:VDKQueueNotifyAboutWrite];
[kqueue setDelegate:self];
这个答案似乎很好地概述了如何设置它,我只是不太明白。 现在我已经初始化了 VDKQueue,如何设置修改文件时发生的情况?
Cocoa Monitor a file for modifications
从另一个答案:
实现非常简单:
- 让你的控制器成为
VDKQueueDelegate; (我在 AppDelegate.h 中添加了<VDKQueueDelegate>)- 声明一个
VDKQueue*ivar / 属性; (这是VDKQueue *kqueue = [[VDKQueue alloc] init];吗?)- 设置委托方法
VDKQueue:receivedNotification:forPath:; (我该怎么做?)- 初始化队列并将其委托设置为控制器本身; (这是
[kqueue setDelegate:self];?)- 使用
addPath:notifyingAbout:添加要观看的资源。 (添加此行[kqueue addPath:path notifyingAbout:VDKQueueNotifyAboutWrite];)那就用委托方法做你的事情吧。
可能是代码中的委托方法?
//
// 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
【问题讨论】:
-
这就是最后一行告诉你的内容:“在委托方法中做你的事情”。委托方法是您的回调。
-
你介意扩展一下吗?我不太明白。我用我拥有的代码更新了上面的几点
标签: objective-c cocoa queue vdkqueue