Scanning for New Documents

Recipe 11-3 works by requesting kqueue notifications in its beginGeneratingDocument-NotificationsInPath: method. Here, it retrieves a file descriptor for the path you supply (in this case, the Documents folder) and requests notifications for add and clear events. It adds this functionality to the current run loop, enabling notifications whenever the monitored folder updates.

Upon receiving that callback, it posts a notification (for example, the custom kDocument-Changed, in the kqueueFired method) and continues watching for new events. This all runs in the primary run loop on the main thread, so the GUI can respond and update itself upon receiving the notification.

The following snippet demonstrates how you might use ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.