可可监视一个文件的修改

可可监视一个文件的修改

本文介绍了可可监视一个文件的修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个指向特定文件的文件路径,我希望在文件发生更改(其内容已被修改)时通知注册。



谷歌搜索,我找不到明确的答案。我已经尝试过使用kqueue和NSWorkspace,但是并没有取得太大的成功。



有什么方法可以做到这一点?

谢谢!



实现非常简单:




  • 让你的控制器成为 VDKQueueDelegate ;
  • declare VDKQueue * ivar / property;
  • 设置委托方法 VDKQueue:receivedNotification:forPath:

  • 初始化队列并将其委托设置为控制器本身;
  • 添加资源来监视addPath :notifyAbout:



然后在委托方法中做您的业务。 $ b

I have a file path to a specific file and I want to register to be notified whenever that file changes (its contents have been modified).

I have tried searching google and I can't find a clear answer. I have experimented with kqueue and NSWorkspace but have not had much success.

What is the proper way to do this?

Thanks!

解决方案

I am using VDKQueue right now - author says it's a refactored and more performant version of UKKQueue.

Implementation was pretty straightforward:

  • let your controller be the VDKQueueDelegate;
  • declare a VDKQueue* ivar / property;
  • setup delegate method VDKQueue:receivedNotification:forPath:;
  • init the queue and set its delegate to the controller itself;
  • add resources to watch with addPath:notifyingAbout:.

Then just do your business in the delegate method.

这篇关于可可监视一个文件的修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:13