Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Last active August 29, 2015 14:04
Show Gist options
  • Save fjolnir/8878e3538a7545a29c4e to your computer and use it in GitHub Desktop.
Save fjolnir/8878e3538a7545a29c4e to your computer and use it in GitHub Desktop.
__weak MyView *self_ = self;
int const fdes = open([path fileSystemRepresentation], O_RDONLY);
_fileWatcher = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fdes,
DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE,
GlobalQueue);
dispatch_source_set_event_handler(_fileWatcher, ^{
unsigned long l = dispatch_source_get_data(_fileWatcher);
if(l & DISPATCH_VNODE_DELETE || l & DISPATCH_VNODE_WRITE) {
dispatch_source_cancel(_fileWatcher);
NSLog(@"Reloading %@", path);
AfterDelay(0.1, ^{
self_.path = path;
});
}
});
dispatch_source_set_cancel_handler(_fileWatcher, ^{
close(fdes);
});
dispatch_resume(_fileWatcher);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment