<?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/"
	>
<channel>
	<title>Jon&#039;s Blog &#187; Cocoa</title>
	<atom:link href="http://jonshier.com/category/programming/cocoa/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonshier.com</link>
	<description>From my mind to your eyes</description>
	<lastBuildDate>Sat, 21 Aug 2010 23:43:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Pixen: Where am I?</title>
		<link>http://jonshier.com/2010/08/21/pixen-where-am-i/</link>
		<comments>http://jonshier.com/2010/08/21/pixen-where-am-i/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 23:43:06 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Pixen]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://jonshier.com/?p=39</guid>
		<description><![CDATA[Well, it has been almost a year since I posted about my adoption of Pixen. While I haven&#8217;t made the progress I had hoped in that time, there is some to report. My current GitHub repository builds on 10.6 only and only with the 32-bit Intel architecture. I&#8217;ve gotten the build down to 3 warnings [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it has been almost a year since I posted about my adoption of Pixen. While I haven&#8217;t made the progress I had hoped in that time, there is some to report. My current <a href="http://github.com/jshier/Pixen" target="_blank">GitHub repository</a> builds on 10.6 only and only with the 32-bit Intel architecture. I&#8217;ve gotten the build down to 3 warnings with all of the options I&#8217;ve enabled but the clang static analyzer still finds over a hundred issues with the code. There are also several bugs still present that I&#8217;ve been trying to narrow down. And, unfortunately, several major parts of Pixen must be rewritten nearly from scratch to build against the 64-bit APIs. Overall, this has turned out to be a much more complicated project that I&#8217;d hoped. Pixen consists of over 25,000 lines of custom code, and that doesn&#8217;t count 3rd party libraries, of which there are several. There are an assortment of custom classes used throughout the program, including custom UI elements and even the basic image type is custom. Combine this with very little in the way of documentation or comments and my new job, and I just haven&#8217;t had the time (or expertise) to delve as far into the code as necessary. So I apologize to anyone hoping for some Pixen progress.</p>
<p>There is still hope however. Pixen: we can rebuild it, we have the technology. Over the coming weeks, time allowing, I&#8217;ll be adding a list of several major issues that need to be addressed for Pixen to move into 2010. These will be posted on my GitHub page, so feel free to comment with any suggestions. I always welcome additional insight into the Pixen code. Even if you don&#8217;t implement features or fix bugs, pointing me in the right direction so I can try to do so myself would be great. I&#8217;ll be focusing on any bugs that pop up (I already have at least one) and the transition to the 64-bit APIs. One of the biggest changes I&#8217;d like to see, even if I don&#8217;t do much with the foundation of the program, is a refreshed UI. I am not a designer by any stretch of the imagination, so if anyone is interested in submitting UI ideas or artwork, especially the UI icons, I would greatly appreciate it.</p>
<p>Thanks for reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://jonshier.com/2010/08/21/pixen-where-am-i/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I&#8217;ve adopted a Pixen!</title>
		<link>http://jonshier.com/2009/09/15/ive-adopted-a-pixen/</link>
		<comments>http://jonshier.com/2009/09/15/ive-adopted-a-pixen/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 03:20:55 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Pixen]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://jonshier.com/?p=31</guid>
		<description><![CDATA[Just over a week ago, Andy Matuschak, of Sparkle fame, asked for volunteers to adopt his Pixen project. It&#8217;s a pixel-based image editor for Mac OS X, and Andy just doesn&#8217;t have the time to maintain it or add features for the upcoming 4.0 release. So I offered my services. I figured I may be [...]]]></description>
			<content:encoded><![CDATA[<p>Just over a week ago, <a title="Andy Matsuchak" href="http://andymatuschak.org/" target="_blank">Andy Matuschak</a>, of <a title="Sparkle" href="http://sparkle.andymatuschak.org/" target="_blank">Sparkle</a> fame, asked for volunteers to <a title="adopt his Pixen project" href="http://blog.andymatuschak.org/post/179455697/adopt-a-pixen" target="_blank">adopt his Pixen project</a>. It&#8217;s a pixel-based image editor for Mac OS X, and Andy just doesn&#8217;t have the time to maintain it or add features for the upcoming 4.0 release. So I offered my services. I figured I may be more successful working on an already established project rather than creating my own from scratch. You can follow <a title="my progress at GitHub" href="http://github.com/jshier/Pixen/" target="_blank">my progress at GitHub</a> and some of my code has already been integrated into the <a title="main Pixen repository" href="http://github.com/philippec/Pixen" target="_blank">main Pixen repository</a> there.</p>
<p>So far my efforts have been limited to project cleanup, modernization, and house keeping. I expect this to be a great learning experience for me going forward and I&#8217;ll be posting code updates as I understand more of the Pixen code. Right now my priorities are fixing all of the warnings I created with new compiler options, updating the Obj-C syntax and Cocoa API&#8217;s used, and taking a look at the performance. Plus we&#8217;ll all be discussing exactly what new features to add for version 4.</p>
]]></content:encoded>
			<wfw:commentRss>http://jonshier.com/2009/09/15/ive-adopted-a-pixen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>BitMaster &#8211; Yet another Mac torrent client&#8230;</title>
		<link>http://jonshier.com/2009/01/27/bitmaster-yet-another-mac-torrent-client/</link>
		<comments>http://jonshier.com/2009/01/27/bitmaster-yet-another-mac-torrent-client/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 19:59:31 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[BitMaster]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://jonshier.com/?p=18</guid>
		<description><![CDATA[Over the last few years I&#8217;ve been teaching myself how to program. Little programs like ultrawar were my first complete programs, but I&#8217;ve read and learned a lot since then. I&#8217;ve been working on a BitTorrent client for the last few years, mostly as a learning exercise but also with the goal of a real [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last few years I&#8217;ve been teaching myself how to program. Little programs like ultrawar were my first complete programs, but I&#8217;ve read and learned a lot since then. I&#8217;ve been working on a BitTorrent client for the last few years, mostly as a learning exercise but also with the goal of a real client at the end. I know Mac OS X doesn&#8217;t really need another torrent client, since Transmission rules and even the mighty uTorrent has a Mac version now. But I wondered what a client that focused solely on Mac technologies would look like, whether it could be any better than those that strive to live across platforms. So I&#8217;ve created BitMaster. Eventually it will be open source from this site, but it&#8217;s still in a very prototype stage (I can only read and parse torrent files, hash downloads, and create torrent files), so I&#8217;ll be posting code excerpts for now. It&#8217;s my hope that having public eyes on the project will help me learn to code and to actually release something, rather than playing with it whenever I&#8217;m in the mood. So here&#8217;s my first bit of code for public scrutiny: my torrent file parsing code.</p>
<p>Obviously, when I first sat down to develop BitMaster I had to determine what functionality I needed first. I chose torrent file parsing, since it seemed like a simple and ubiquitous part of torrent client development. You can see my first attempt a this code in my previous entry &#8220;Learning through doing&#8230;&#8221; which is quite rough. After feedback from various people online, it now looks like this:</p>
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  JSbdecoder.m</span>
<span style="color: #11740a; font-style: italic;">//  BitMaster</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Jon Shier on 4/9/07.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2007 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #6e371a;">#import &quot;JSbdecoder.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> JSbdecoder
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> decodeTorrentFile<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> pathToTorrentFile <span style="color: #002200;">&#123;</span>
    torrentData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> dataWithContentsOfFile<span style="color: #002200;">:</span> pathToTorrentFile options<span style="color: #002200;">:</span> NSUncachedRead error<span style="color: #002200;">:</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    rawTorrentData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>torrentData bytes<span style="color: #002200;">&#93;</span>;
    position <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self convertObjectDataToStrings<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self bdecodeData<span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> bdecodeData <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>methodArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> array<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">do</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>rawTorrentData<span style="color: #002200;">&#91;</span>position<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">'i'</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            position<span style="color: #002200;">++</span>;
            <span style="color: #002200;">&#91;</span>methodArray addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self decodeInt<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>rawTorrentData<span style="color: #002200;">&#91;</span>position<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">'l'</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            position<span style="color: #002200;">++</span>;
            <span style="color: #002200;">&#91;</span>methodArray addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self decodeList<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>rawTorrentData<span style="color: #002200;">&#91;</span>position<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">'d'</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            position<span style="color: #002200;">++</span>;
            <span style="color: #002200;">&#91;</span>methodArray addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self decodeDictionary<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">isdigit</span><span style="color: #002200;">&#40;</span>rawTorrentData<span style="color: #002200;">&#91;</span>position<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>methodArray addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self decodeBytes<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>rawTorrentData<span style="color: #002200;">&#91;</span>position<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">'e'</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            position<span style="color: #002200;">++</span>;
            <span style="color: #11740a; font-style: italic;">//Should only hit this when at the end of lists, dictionaries, or integers.</span>
            <span style="color: #a61390;">break</span>;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
            NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Error decoding torrent. Unexpected character '%c' at position %d.&quot;</span>, rawTorrentData<span style="color: #002200;">&#91;</span>position<span style="color: #002200;">&#93;</span>, position<span style="color: #002200;">&#41;</span>;
            <span style="color: #a61390;">return</span> methodArray;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span>position &lt; <span style="color: #002200;">&#91;</span>torrentData length<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> methodArray;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> decodeInt <span style="color: #002200;">&#123;</span>
    NSUInteger methodPosition <span style="color: #002200;">=</span> position;
    <span style="color: #a61390;">while</span><span style="color: #002200;">&#40;</span>rawTorrentData<span style="color: #002200;">&#91;</span>position<span style="color: #002200;">&#93;</span> <span style="color: #002200;">!=</span> <span style="color: #bf1d1a;">'e'</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
       position<span style="color: #002200;">++</span>;
    <span style="color: #002200;">&#125;</span>
    position<span style="color: #002200;">++</span>;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithInteger<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>torrentData subdataWithRange<span style="color: #002200;">:</span> NSMakeRange<span style="color: #002200;">&#40;</span>methodPosition, <span style="color: #002200;">&#40;</span>position <span style="color: #002200;">-</span> methodPosition<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span> bytes<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> integerValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> decodeBytes <span style="color: #002200;">&#123;</span>
    NSUInteger methodPosition <span style="color: #002200;">=</span> position;
    <span style="color: #a61390;">while</span><span style="color: #002200;">&#40;</span>rawTorrentData<span style="color: #002200;">&#91;</span>position<span style="color: #002200;">&#93;</span> <span style="color: #002200;">!=</span> <span style="color: #bf1d1a;">':'</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        position<span style="color: #002200;">++</span>;
    <span style="color: #002200;">&#125;</span>
    NSUInteger bytesLength <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>torrentData subdataWithRange<span style="color: #002200;">:</span> NSMakeRange<span style="color: #002200;">&#40;</span>methodPosition, <span style="color: #002200;">&#40;</span>position <span style="color: #002200;">-</span> methodPosition<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span> bytes<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> integerValue<span style="color: #002200;">&#93;</span>;
    position<span style="color: #002200;">++</span>;
    methodPosition <span style="color: #002200;">=</span> position;
    position <span style="color: #002200;">+=</span> bytesLength;
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>torrentData subdataWithRange<span style="color: #002200;">:</span> NSMakeRange<span style="color: #002200;">&#40;</span>methodPosition, bytesLength<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> decodeList <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self bdecodeData<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> decodeDictionary <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>methodDictionary <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> dictionary<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>methodArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithArray<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self bdecodeData<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>NSUInteger i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #002200;">&#91;</span>methodArray count<span style="color: #002200;">&#93;</span>; i <span style="color: #002200;">+=</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>methodDictionary setObject<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>methodArray objectAtIndex<span style="color: #002200;">:</span> i <span style="color: #002200;">+</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>methodArray objectAtIndex<span style="color: #002200;">:</span> i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> methodDictionary;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> convertObjectDataToStrings<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> object <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>object conformsToProtocol<span style="color: #002200;">:</span> <span style="color: #a61390;">@protocol</span><span style="color: #002200;">&#40;</span><span style="color: #2a6f76;">NSFastEnumeration</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>valueArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> array<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>object isKindOfClass<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> enumeratedObject <span style="color: #a61390;">in</span> object<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #002200;">&#91;</span>valueArray addObject<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>self convertObjectDataToStrings<span style="color: #002200;">:</span> enumeratedObject<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#125;</span>
            <span style="color: #a61390;">return</span> valueArray;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>object isKindOfClass<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            valueArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>object allValues<span style="color: #002200;">&#93;</span> mutableCopy<span style="color: #002200;">&#93;</span>;
            <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>keyArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> arrayWithArray<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>object allKeys<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
            <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>NSUInteger i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #002200;">&#91;</span>keyArray count<span style="color: #002200;">&#93;</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #002200;">&#91;</span>keyArray replaceObjectAtIndex<span style="color: #002200;">:</span> i withObject<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>self convertObjectDataToStrings<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>keyArray objectAtIndex<span style="color: #002200;">:</span> i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#125;</span>
            <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>NSUInteger i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #002200;">&#91;</span>valueArray count<span style="color: #002200;">&#93;</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>keyArray objectAtIndex<span style="color: #002200;">:</span> i<span style="color: #002200;">&#93;</span> isEqualToString<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;pieces&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                    <span style="color: #002200;">&#91;</span>valueArray replaceObjectAtIndex<span style="color: #002200;">:</span> i withObject<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>self convertObjectDataToStrings<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>valueArray objectAtIndex<span style="color: #002200;">:</span> i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
                <span style="color: #002200;">&#125;</span>
            <span style="color: #002200;">&#125;</span>
            <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> dictionaryWithObjects<span style="color: #002200;">:</span> valueArray forKeys<span style="color: #002200;">:</span> keyArray<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>object isKindOfClass<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> object;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>object isKindOfClass<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithBytes<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>object bytes<span style="color: #002200;">&#93;</span> length<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>object length<span style="color: #002200;">&#93;</span> encoding<span style="color: #002200;">:</span> NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Unexpected object %@ of class %@&quot;</span>, object, <span style="color: #002200;">&#91;</span>object class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> object;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>
<p>This code is much faster, cleaner, and accurate than the previous attempt. But it&#8217;s still inelegant in a lot of ways. For example, I store the torrent file data within both an NSData object (for the subdata* methods) and a char array (so I can access individual characters to iterate over). Surely there must be a better way, I just haven&#8217;t found it. For a few of my methods, there must be a better way of converting to an NSNumber object than getting a subdata, making it a string, and making the string a number. Seems quite obtuse compared to the conversions I&#8217;ve seen in other languages.</p>
<p>Well, that&#8217;s all for now. I&#8217;ll try to get this post out and around so I can get feed back, so feel free to leave comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://jonshier.com/2009/01/27/bitmaster-yet-another-mac-torrent-client/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.855 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-08-28 23:06:50 -->
<!-- Compression = gzip -->