ZDCFilesystemMonitor

@interface ZDCFilesystemMonitor : NSObject

Monitors the filesystem for changes to a file or directory, and uses a block-based notification system to alert you when changes are signaled by the OS.

  • Creates a new monitor designed to watch the given file for changes. The url should represent a file, not a directory.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithFileURL:(nonnull NSURL *)fileURL;

    Swift

    init(fileURL: URL)
  • Creates a new monitor designed to watch the given directory for changes. The url should represent a directory, not a file.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithDirectoryURL:(nonnull NSURL *)directoryURL;

    Swift

    init(directoryURL: URL)
  • url

    The URL specified during init

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSURL *_Nonnull url;

    Swift

    var url: URL { get }
  • YES if initWithDirectoryURL was used. NO otherwise

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL isDirectory;

    Swift

    var isDirectory: Bool { get }
  • Starts monitoring the url for changes.

    Declaration

    Objective-C

    - (BOOL)monitorWithMask:(dispatch_source_vnode_flags_t)mask
                      queue:(nullable dispatch_queue_t)queue
                      block:(nonnull void (^)(dispatch_source_vnode_flags_t))block;

    Swift

    func monitor(withMask mask: UInt, queue: DispatchQueue?, block: @escaping (UInt) -> Void) -> Bool

    Parameters

    mask

    A bitmask that lists the options for monitoring the url. There are class methods that may be of assistance: +vnode_flags+all & +vnode_flags_data_changed.

    queue

    The dispatch queue on which to invoke your block.

    block

    The block to invoke when the OS informs us of changes to the file/directory.

  • Returns a mask with every possible event

    Declaration

    Objective-C

    + (dispatch_source_vnode_flags_t)vnode_flags_all;

    Swift

    class func vnode_flags_all() -> UInt
  • Returns a mask with flags only for when the actual bytes change

    Declaration

    Objective-C

    + (dispatch_source_vnode_flags_t)vnode_flags_data_changed;

    Swift

    class func vnode_flags_data_changed() -> UInt
  • Returns a string listing the flags specified by the given mask

    Declaration

    Objective-C

    + (nonnull NSString *)vnode_flags_description:
        (dispatch_source_vnode_flags_t)mask;

    Swift

    class func vnode_flags_description(_ mask: UInt) -> String