0

You can use NSMetadataQuery to detect any file changes within the home directory of a user. However it seems like it doesn't index and therefor detect any file changes in the users Library path.

Luckily for my purpose I know exactly where my file is and I like to know if the files changes and react on it. Do I need to right my own listener class? That will mimic the behavior of NSMetadataQuery by checking if the modification date changes or is there a simpeler way?

    var resource: AnyObject?
    fileURL?.getResourceValue(&resource, forKey: NSURLContentModificationDateKey, error: nil)
    if let fileDate = resource as? NSDate {
        println(fileDate)
    }
Mark
  • 16,906
  • 20
  • 84
  • 117

1 Answers1

0

If you only need to watch a single file, you can use libdispatch or kqueue.

For watching folders, there's the FSEvents API.

Community
  • 1
  • 1