<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>[[Blog alloc] init]</title>
	<atom:link href="http://cocoacafe.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cocoacafe.wordpress.com</link>
	<description>Sample code, tricks, and thoughts from a Mac developer.</description>
	<lastBuildDate>Sat, 15 Jan 2011 17:06:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='cocoacafe.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>[[Blog alloc] init]</title>
		<link>http://cocoacafe.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://cocoacafe.wordpress.com/osd.xml" title="[[Blog alloc] init]" />
	<atom:link rel='hub' href='http://cocoacafe.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The fragile base class problem</title>
		<link>http://cocoacafe.wordpress.com/2007/06/20/the-fragile-base-class-problem/</link>
		<comments>http://cocoacafe.wordpress.com/2007/06/20/the-fragile-base-class-problem/#comments</comments>
		<pubDate>Thu, 21 Jun 2007 03:45:34 +0000</pubDate>
		<dc:creator>jrc</dc:creator>
				<category><![CDATA[ObjC]]></category>

		<guid isPermaLink="false">http://cocoacafe.wordpress.com/2007/06/20/the-fragile-base-class-problem/</guid>
		<description><![CDATA[Why did SafariPlus start crashing on Mac OS X 10.4.10? The answer lies in what is known as the fragile base class problem. In standard Objective C runtimes, including Apple&#8217;s, classes are actually plain C structures, defined in /usr/include/objc/objc-class.h. (This hints at how toll-free bridging is possible between CoreFoundation&#8217;s C data structures and Foundation&#8217;s Objective [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cocoacafe.wordpress.com&amp;blog=1251289&amp;post=6&amp;subd=cocoacafe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Why did <a href="http://web.mac.com/jrc/SafariPlus/">SafariPlus</a> start crashing on Mac OS X 10.4.10?</p>
<p>The answer lies in what is known as the <a href="http://en.wikipedia.org/wiki/Fragile_base_class">fragile base class problem</a>.</p>
<p>In standard Objective C runtimes, including Apple&#8217;s, classes are actually plain C structures, defined in <tt>/usr/include/objc/objc-class.h</tt>. (This hints at how <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CarbonCocoaDoc/Articles/interchangeableDataTypes.html">toll-free bridging</a> is possible between CoreFoundation&#8217;s C data structures and Foundation&#8217;s Objective C objects.)</p>
<p>Objective C programmers are happily aware that methods are dynamically bound at runtime. This is the secret sauce behind much of Objective C&#8217;s magic, such as categories, message forwarding, and runtime introspection. However, unlike with method dispatching, which works by name, instance variables are referenced by their memory offsets in the class structure and statically bound at compile time. So if the base class structure ever changes in size, or if the instance variables are rearranged, subclasses need to recompiled as well, or the layout of objects in memory will be incorrect and your application will crash. (This is why Apple tends to pad base class structures, if not hide them outright, for forward compatibility; the class definition of NSNotificationCenter shows an example of this.)</p>
<p>Note that the fragile base class problem doesn&#8217;t affect most application developers, because in application code, your base classes and your subclasses tend to be compiled simultaneously, and you assume that the base classes you&#8217;re using in frameworks won&#8217;t be changing. So unless you&#8217;re writing a public API, you don&#8217;t generally need to worry about this problem.</p>
<p>Nevertheless, even for application developers, it&#8217;s good to understand how Objective C really works. Situations like this reveal how Objective C really is merely a thin layer on top of C. In fact, when you write Objective C syntax such as <tt>[object message:arg]</tt>, it&#8217;s really shorthand for primitive C function calls such as <b>objc_msgSend()</b>. (This is why if you try to send a message to a released object, you&#8217;ll see <tt>objc_msgSend</tt> in the backtrace of the crash.)</p>
<p>The following is straight C code. It shouldn&#8217;t be hard to read it and translate it to its Objective C equivalent.</p>
<p><code>#include &lt;objc/objc.h&gt;<br />
</code></p>
<pre>void * pool = objc_msgSend(objc_lookUpClass("NSAutoreleasePool"), sel_getUid("alloc"));
objc_msgSend(pool, sel_getUid("init"));

void * date = objc_msgSend(objc_lookUpClass("NSDate"), sel_getUid("date"));
void * string = objc_msgSend(date, sel_getUid("description"));
printf("%s\n", objc_msgSend(string, sel_getUid("UTF8String")));

objc_msgSend(pool, sel_getUid("release"));
</pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/cocoacafe.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/cocoacafe.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cocoacafe.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cocoacafe.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cocoacafe.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cocoacafe.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cocoacafe.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cocoacafe.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cocoacafe.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cocoacafe.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cocoacafe.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cocoacafe.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cocoacafe.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cocoacafe.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cocoacafe.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cocoacafe.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cocoacafe.wordpress.com&amp;blog=1251289&amp;post=6&amp;subd=cocoacafe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cocoacafe.wordpress.com/2007/06/20/the-fragile-base-class-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7c9805edc21e2627ed8d6edc8a52802d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jrc</media:title>
		</media:content>
	</item>
		<item>
		<title>TableColumnDateFormatter</title>
		<link>http://cocoacafe.wordpress.com/2007/06/20/tablecolumndateformatter/</link>
		<comments>http://cocoacafe.wordpress.com/2007/06/20/tablecolumndateformatter/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 18:54:36 +0000</pubDate>
		<dc:creator>jrc</dc:creator>
				<category><![CDATA[AppKit]]></category>

		<guid isPermaLink="false">http://cocoacafe.wordpress.com/2007/06/20/tablecolumndateformatter/</guid>
		<description><![CDATA[Have you ever noticed how Finder treats dates in list view? If the column is wide enough, the date is displayed in a nice long format: Wednesday, January 3, 2007, 12:34 PM As the table column is resized, the date is dynamically reformatted to fit in the available width: Wednesday, January 3, 2007, 12:34 PM [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cocoacafe.wordpress.com&amp;blog=1251289&amp;post=5&amp;subd=cocoacafe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have you ever noticed how Finder treats dates in list view?</p>
<p>If the column is wide enough, the date is displayed in a nice long format:</p>
<blockquote><p>Wednesday, January 3, 2007, 12:34 PM</p></blockquote>
<p>As the table column is resized, the date is dynamically reformatted to fit in the available width:</p>
<blockquote><p>Wednesday, January 3, 2007, 12:34 PM<br />
January 3, 2007, 12:34 PM<br />
Jan 3, 2007, 12:34 PM<br />
1/3/07, 12:34 PM<br />
1/3/07</p></blockquote>
<p>It also displays relative date strings if the date is recent enough:</p>
<blockquote><p>Today, 12:34 PM<br />
Yesterday, 12:34 PM</p></blockquote>
<p>This level of craftsmanship and attention to detail is what made the original Macintosh Finder so respected and loved. It&#8217;s nice that this feature has been carried over to the Mac OS X Finder.</p>
<p>Unfortunately, the standard Cocoa classes don&#8217;t give you this behavior for free.</p>
<p><b>TableColumnDateFormatter</b> is a subclass of NSDateFormatter which implements similar behavior. To use it, drop the TableColumnDateFormatter folder into your project, then add the following code:</p>
<p><code>#import "TableColumnDateFormatter.h"</code></p>
<pre>- (void) awakeFromNib
{
	TableColumnDateFormatter * df = [[TableColumnDateFormatter alloc] init];
	NSTableColumn * tableColumn = [tableView tableColumnWithIdentifier:@"date"];
	[df setTableColumn:tableColumn];
	[df release];
}
</pre>
<ul>
<li>Sources: <a href="http://homepage.mac.com/jrc/contrib/cocoa/TableColumnDateFormatter.zip">TableColumnDateFormatter.zip</a> (6K)</li>
</ul>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/cocoacafe.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/cocoacafe.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cocoacafe.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cocoacafe.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cocoacafe.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cocoacafe.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cocoacafe.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cocoacafe.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cocoacafe.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cocoacafe.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cocoacafe.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cocoacafe.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cocoacafe.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cocoacafe.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cocoacafe.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cocoacafe.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cocoacafe.wordpress.com&amp;blog=1251289&amp;post=5&amp;subd=cocoacafe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cocoacafe.wordpress.com/2007/06/20/tablecolumndateformatter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7c9805edc21e2627ed8d6edc8a52802d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jrc</media:title>
		</media:content>
	</item>
		<item>
		<title>BundleUserDefaults</title>
		<link>http://cocoacafe.wordpress.com/2007/06/18/bundleuserdefaults/</link>
		<comments>http://cocoacafe.wordpress.com/2007/06/18/bundleuserdefaults/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 04:23:07 +0000</pubDate>
		<dc:creator>jrc</dc:creator>
				<category><![CDATA[Foundation]]></category>

		<guid isPermaLink="false">http://cocoacafe.wordpress.com/2007/06/18/bundleuserdefaults/</guid>
		<description><![CDATA[If you&#8217;re writing a plug-in or framework, how do you get NSUserDefaults to write out preferences to your own persistent domain (a.k.a. application identifier)? Even though you can add application suites to the search list, NSUserDefaults always writes out to the main application bundle&#8217;s domain. It turns out that you can&#8217;t, at least not directly. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cocoacafe.wordpress.com&amp;blog=1251289&amp;post=4&amp;subd=cocoacafe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re writing a plug-in or framework, how do you get <a>NSUserDefaults</a> to write out preferences to your own persistent domain (a.k.a. application identifier)? Even though you can add application suites to the search list, NSUserDefaults always writes out to the main application bundle&#8217;s domain.</p>
<p>It turns out that you can&#8217;t, at least not directly. You have to use the <a href="http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFPreferences/">CFPreferences</a> API.</p>
<p><strong>BundleUserDefaults</strong> is a subclass of NSUserDefaults which wraps around CFPreferences and allows you to specify a persistent domain name. Just initialize it with your domain string, and use it like you&#8217;d normally use NSUserDefaults.</p>
<p>You can even use your instance of BundleUserDefaults with <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSUserDefaultsController_Class/">NSUserDefaultsController</a> by calling an undocumented setter method <tt>-[NSUserDefaultsController _setDefaults:]</tt>:</p>
<p><code>+ (void)initialize<br />
{<br />
	BundleUserDefaults * ud = [[BundleUserDefaults alloc] initWithPersistentDomainName:@"com.example.test"];<br />
	[[NSUserDefaultsController sharedUserDefaultsController] _setDefaults:ud];<br />
	[ud release];<br />
}<br />
</code></p>
<p>This makes it really easy to implement a preferences panel in your plug-in or shared framework, without writing any additional code. Just use <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/">Cocoa Bindings</a> to bind to the shared user defaults controller, paste in the above code snippet, and you&#8217;re done.</p>
<ul>
<li>Sources: <a href="http://homepage.mac.com/jrc/contrib/cocoa/BundleUserDefaults.h">BundleUserDefaults.h</a> and <a href="http://homepage.mac.com/jrc/contrib/cocoa/BundleUserDefaults.h">BundleUserDefaults.m</a></li>
</ul>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/cocoacafe.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/cocoacafe.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cocoacafe.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cocoacafe.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cocoacafe.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cocoacafe.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cocoacafe.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cocoacafe.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cocoacafe.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cocoacafe.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cocoacafe.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cocoacafe.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cocoacafe.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cocoacafe.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cocoacafe.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cocoacafe.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cocoacafe.wordpress.com&amp;blog=1251289&amp;post=4&amp;subd=cocoacafe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cocoacafe.wordpress.com/2007/06/18/bundleuserdefaults/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7c9805edc21e2627ed8d6edc8a52802d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jrc</media:title>
		</media:content>
	</item>
		<item>
		<title>Searching for files by name</title>
		<link>http://cocoacafe.wordpress.com/2007/06/17/fscatalogsearch/</link>
		<comments>http://cocoacafe.wordpress.com/2007/06/17/fscatalogsearch/#comments</comments>
		<pubDate>Sun, 17 Jun 2007 21:31:27 +0000</pubDate>
		<dc:creator>jrc</dc:creator>
				<category><![CDATA[Carbon]]></category>

		<guid isPermaLink="false">http://cocoacafe.wordpress.com/2007/06/17/fscatalogsearch/</guid>
		<description><![CDATA[Why is it so hard to search for files using Spotlight? Spotlight sometimes misses files, namely those tucked away inside bundle structures or system directories. Unfortunately, because Spotlight is designed to optimize general searches, it falls short when you&#8217;re trying to do specific searches. Find File, Sherlock, and Spotlight You might remember that back in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cocoacafe.wordpress.com&amp;blog=1251289&amp;post=3&amp;subd=cocoacafe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Why is it so hard to search for files using Spotlight?</p>
<p>Spotlight sometimes misses files, namely those tucked away inside bundle structures or system directories. Unfortunately, because Spotlight is designed to optimize general searches, it falls short when you&#8217;re trying to do specific searches.</p>
<p><b>Find File, Sherlock, and Spotlight</b></p>
<p>You might remember that back in System 7.5 (1995), Apple introduced a <a href="http://kb.wisc.edu/helpdesk/page.php?id=255">Find File</a> utility which allowed one to search a volume by file name or other attributes. It was very fast, thanks to a specific design characteristic of the Mac&#8217;s native file system: HFS+ stores its catalog data in a centralized manner, instead of distributed across directories. This approach makes the catalog data more susceptible to corruption, but it also makes file searches very fast. There is no need to index file names, because the file system is inherently indexed.</p>
<p>With Sherlock, introduced in Mac OS 8.5 (1997), Apple started moving toward the find-by-content problem space. Spotlight, introduced in Mac OS X v10.4 (2005), represents Apple&#8217;s latest solution to the problem of search. The underlying indexing technology used by Spotlight is an evolution of Apple&#8217;s <a href="http://developer.apple.com/documentation/MacOSX/Conceptual/OSX_Technology_Overview/AppTechnology/chapter_5_section_17.html">SearchKit</a> technology (in turn based on Apple Information Access Toolkit, a.k.a. VTwin), but the Spotlight user experience is a completely new approach, based on the idea of a single search field that applies to all content by default. It&#8217;s basically the same thing as what Google calls <a href="http://googleblog.blogspot.com/2007/05/universal-search-best-answer-is-still.html">universal search</a>, but Spotlight obviously applies the idea across the desktop operating system instead of the Internet. </p>
<p>The patent that covers Spotlight, <a href="http://patft.uspto.gov/netacgi/nph-Parser?u=%2Fnetahtml%2Fsrchnum.htm&amp;Sect1=PTO1&amp;Sect2=HITOFF&amp;p=1&amp;r=1&amp;l=50&amp;f=G&amp;d=PALL&amp;s1=6847959.PN.&amp;OS=PN/6847959&amp;RS=PN/6847959">6847959</a> (&#8220;Universal interface for retrieval of information in a computer system&#8221;), was actually filed in 2000, revealing that Apple had been working on universal search for several years before Spotlight was ever introduced. Apple&#8217;s first implementation of universal search was actually in <a>iTunes</a> (2001).</p>
<p>Spotlight&#8217;s strength, however, is its greatest weakness. If you know exactly what you want to search for, it takes a bit more work on your part to set up a filename-only query (and you can&#8217;t do it from the Spotlight menu). Even so, many system directories and temporary files are omitted from the search as a performance optimization, which can pose a real problem if those are the files you&#8217;re looking for. This effectively also means that the search results are not guaranteed to be complete. In practice, we&#8217;ve gone a step backwards from the simple, reliable Find File of System 7.5.</p>
<p><b>find and locate</b></p>
<p>There are also two standard Unix command-line tools which search the file system. The first command-line tool is <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/find.1.html">find</a>. In additional to its awkward interface, <tt>find</tt> performs a walk of the directory hierarchy because it doesn&#8217;t know about HFS+. This makes <tt>find</tt> slow, although it provides more complete search results than Spotlight.</p>
<p>The second command-line tool is <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/locate.1.html">locate</a>. Unlike <tt>find</tt>, locate uses a index, so searching is fast. Unfortunately (and unlike with Spotlight), the index is only updated automatically when the <tt>/etc/weekly</tt> script runs, which isn&#8217;t guaranteed to happen, especially if your computer tends to be asleep.</p>
<p><b>FSCatalogSearch()</b></p>
<p>It&#8217;s not obvious, but the functionality of Find File does still exist on Mac OS X. At the heart of Find File is a Carbon File Manager function called <b>FSCatalogSearch</b>. You create an iterator and pass in a struct of search options, and FSCatalogSearch uses that iterator to search until the iterator is exhausted.</p>
<p>Here&#8217;s a simple command-line tool which uses FSCatalogSearch to search for files by name.</p>
<blockquote><p>
<tt>usage: findfile [-r &lt;volume&gt;] &lt;name&gt;</tt>
</p></blockquote>
<ul>
<li>Binary: <a href="http://homepage.mac.com/jrc/contrib/tools/findfile">findfile</a> (46K, Mac OS X v10.4)</li>
<li>Sources: <a href="http://homepage.mac.com/jrc/contrib/tools/findfile.zip">findfile.zip</a> (5K)</li>
</ul>
<p><b>Comparison</b></p>
<p>The best technology for finding files by name, as measured by both completeness of results and performance, is FSCatalogSearch. Ironically, it does not have a visible interface in Mac OS X v10.4. The best approximation is to set up a Smart Folder which searches by Filename or even Raw Query.</p>
<p><a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/mdfind.1.html">mdfind</a> is a command-line interface to the central metadata store that underlies Spotlight. Perversely, <tt>mdfind</tt> offers better results than the Finder interface to the same technology. The only difference between <tt>mdfind</tt> and FSCatalogSearch is that mdfind does not enter bundles, so that <tt>/Applications/iSync.app/Contents/Resources/orangelight.tiff</tt>, for example, won&#8217;t be found.</p>
<table border="1">
<tr>
<th></th>
<th>Hits</th>
<th>Time</th>
</tr>
<tr>
<td><b>FSCatalogSearch</b> (&#8220;<tt>findfile orange</tt>&#8220;)</td>
<td><font color="green">29 paths</font></td>
<td>4 sec</td>
</tr>
<tr>
<td><b>find</b> (&#8220;<tt>find -x / -iname "*orange*"</tt>&#8220;)</td>
<td><font color="green">29 paths</font></td>
<td><font color="red">1 min</font></td>
</tr>
<tr>
<td><b>mdfind</b> (&#8220;<tt>mdfind -onlyin / "(kMDItemFSName =='*orange*'c)"</tt>&#8220;)
</td>
<td>25 paths</td>
<td>4 sec</td>
</tr>
<tr>
<td><b>locate</b> (&#8220;<tt>locate orange | grep -v /Volumes</tt>&#8220;)</td>
<td>4 paths</td>
<td>0.2 sec</td>
</tr>
<tr>
<td><b>Spotlight</b> (&#8220;Filename contains orange&#8221; on startup disk)
</td>
<td>3 paths</td>
<td>5 sec</td>
</tr>
</table>
<p>P.S. Here&#8217;s a tip. You can actually enclose your search terms in quotation marks:</p>
<blockquote><p>&#8220;example&#8221;</p></blockquote>
<p>Spotlight will limit your search by name. (This only works from the Spotlight menu.)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/cocoacafe.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/cocoacafe.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cocoacafe.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cocoacafe.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cocoacafe.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cocoacafe.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cocoacafe.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cocoacafe.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cocoacafe.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cocoacafe.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cocoacafe.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cocoacafe.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cocoacafe.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cocoacafe.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cocoacafe.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cocoacafe.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cocoacafe.wordpress.com&amp;blog=1251289&amp;post=3&amp;subd=cocoacafe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cocoacafe.wordpress.com/2007/06/17/fscatalogsearch/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7c9805edc21e2627ed8d6edc8a52802d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jrc</media:title>
		</media:content>
	</item>
	</channel>
</rss>
