mardi 30 juin 2015

How can you detect file changes with a OSX Library directory?

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)
    }

Aucun commentaire:

Enregistrer un commentaire