13.07.2015 Views

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 5: Using the Filesystem 147- (void) accommodatePresentedItemDeletionWithCompletionHandler: (void (^)(NSError *))completionHandler{fprintf(stdout, "FolderInfo file being deleted.\n");// deletion is relatively simple for us to handle-- we'll ensure we've got the latestcontents cached in memory// and let it go[self loadFile];completionHandler(NULL);}- (void) presentedItemDidMoveToURL: (NSURL *) newURL{// store the new URL_fileURL = [newURL copy];}- (void) presentedItemDidChange{// load the new contents[self loadFile];}Thus ends your whistle-stop tour of the NSFileCordinator APIs. I strongly encourage you to readthrough the very extensive documentation provided by Apple to get a thorough understanding ofthe likely situations in which file presenters and the file coordination system work together. ThisAPI provides a wonderfully simple and clean way to handle some very thorny problems, and ifeveryone adopts it, then it will make everyone else’s tasks that much easier.Searching with SpotlightSo far just about everything I’ve talked about has been based around the concepts of files andfolders. However, with folder hierarchies getting deeper and more complicated, and with disksizes and their contents growing in tandem, a manual trawl through the filesystem isn’t thesimple task it once was. Apple’s solution to this revolves around a metadata searching utilitycalled Spotlight.You are likely already familiar with Spotlight. It’s always accessible on the Mac through themagnifying-glass icon at the top right of the screen. As you type into the search field revealed byclicking on that icon, results appear almost instantly, matching against file names, the contentof recently visited links, e-mails, and even the contents of certain types of documents. Thistechnology isn’t only available through the OS X menu bar, however; a full and rich API underliesit and provides developers with the ability to execute queries (in a properly asynchronousfashion, of course) against the Spotlight metadata and content database.There are a lot of different metadata attributes upon which you can search, and you can specifydifferent queries to help locate some items. For example, to locate all if the files in your homefolder that were modified within the last five minutes, you can open the Terminal application andtype ‘mdfind -onlyin ~ 'kMDItemContentModificationDate > $time.now(-300)'. An exampleresult is shown in Listing 5-33.www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!