<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>No Content, No Fuss: My first Cocoa steps</title>
    <link>http://anil.recoil.org/blog/articles/2006/07/15/my-first-cocoa-steps</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Anil Madhavapeddy</description>
    <item>
      <title>My first Cocoa steps</title>
      <description>&lt;p&gt;&lt;a href="http://anil.recoil.org/blog/files/mlgalleryedit.png" rel="lightbox" title="mlgalleryedit screenshot"&gt;&lt;img style="float:right" src="/blog/files/mlgalleryedit-thumb.png" alt="mlgalleryedit" /&gt; &lt;/a&gt;
Ever since I got my first Powerbook back in 2000, I've been meaning to learn Cocoa and Carbon to hack on MacOS X GUIs.  On the flight over to San Francisco, I finally found the uninterrupted time to knock up a simple GUI interface to my &lt;a href="http://anil.recoil.org/gallery"&gt;gallery&lt;/a&gt; meta-data files.  Overall, the experience was pretty positive.  It's definitely more satisfying than my experiences with Windows and UNIX GUI programming, mainly because the result is so pretty!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Objective-C has a really nice dynamic message dispatch mechanism, used to good effect by Cocoa.  The &lt;a href="http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Concepts/AutoreleasePools.html"&gt;autorelease&lt;/a&gt; mechanism plays well with C memory management to provide a reference-counted interface which is fairly well abstracted.  My application still leaks memory like a sieve though; I miss OCaml!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cocoa provides a huge number of ways to do the same thing.  &lt;a href="http://www.cocoadevcentral.com/articles/000080.php"&gt;Bindings&lt;/a&gt; are the fancy new thing, &lt;a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/chapter_5_section_4.html"&gt;MVC&lt;/a&gt; is the older "paradigm", and of course &lt;a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CarbonCocoaDoc/Articles/CarbonCocoaComm.html"&gt;Carbon&lt;/a&gt; predates all of this.  The documentation is a bit of a mess for a beginner to the framework, as crucial facts on how to get simple stuff done are scattered across a myriad of documents.  Thanks Google.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tiger has some funky new Cocoa controls.  Check out the use of &lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/BindingsText/NSTokenField.html"&gt;NSTokenField&lt;/a&gt; on the screenshot which lets the tag entry field auto-complete just like Mail does!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The APIs can be unfortunately verbose at times, as the following code snippet which does a little bit of simple string manipulation shows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt; NSArray *a = [tag componentsSeparatedByString:@&amp;quot; &amp;quot;];
    iter2 = [a objectEnumerator];
    while (s = [iter2 nextObject]) {
        NSString *e = [s stringByTrimmingCharactersInSet:
            [NSCharacterSet whitespaceCharacterSet]];
         if (![e isEqual:@&amp;quot;&amp;quot;]) 
            [tags addObject:[e retain]];
    }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I'm quite looking forward to doing more work on this simple application now that the basics are mastered.  Hmm... preferences panes next, then a bit of Cocoa bindings, and perhaps I feel OCamlCocoa coming on...&lt;/p&gt;</description>
      <pubDate>Sat, 15 Jul 2006 03:45:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:2ad19e99-c73a-41b6-9af4-36eb6d17ffdb</guid>
      <author>anil@recoil.org (Anil Madhavapeddy)</author>
      <link>http://anil.recoil.org/blog/articles/2006/07/15/my-first-cocoa-steps</link>
      <category>hacking</category>
      <trackback:ping>http://anil.recoil.org/blog/articles/trackback/78</trackback:ping>
    </item>
    <item>
      <title>"My first Cocoa steps" by Anil Madhavapeddy</title>
      <description>&lt;p&gt;Yeah, and NSPredicate seems like an interesting way to do filtering/search stuff.&lt;/p&gt;</description>
      <pubDate>Sat, 15 Jul 2006 16:15:04 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:a7179628-3d22-45e4-897d-a1ea01cb1039</guid>
      <link>http://anil.recoil.org/blog/articles/2006/07/15/my-first-cocoa-steps#comment-80</link>
    </item>
    <item>
      <title>"My first Cocoa steps" by Alastair Tse</title>
      <description>&lt;p&gt;Yeah, objectEnumerators can be a pain sometimes, especially when you're used to functional constructs like map and filter. In NSArray and NSMutableArray there's a way to map a function on to each element of the array which is like a halfway point between the two.&lt;/p&gt;

&lt;p&gt;I actually love the long function names, no more guessing what atoi and ioctl means!&lt;/p&gt;</description>
      <pubDate>Sat, 15 Jul 2006 09:58:16 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:991e6716-1f11-43b2-8ecb-522fc961b32a</guid>
      <link>http://anil.recoil.org/blog/articles/2006/07/15/my-first-cocoa-steps#comment-79</link>
    </item>
  </channel>
</rss>
