Cocoa Monitor a file for modifications

后端 未结 2 1705
灰色年华
灰色年华 2020-12-10 00:08

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 goog

2条回答
  •  囚心锁ツ
    2020-12-10 00:40

    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.

提交回复
热议问题