<?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></title>
	<atom:link href="http://excitabyte.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://excitabyte.wordpress.com</link>
	<description></description>
	<lastBuildDate>Wed, 18 Jan 2012 15:09:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='excitabyte.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title></title>
		<link>http://excitabyte.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://excitabyte.wordpress.com/osd.xml" title="" />
	<atom:link rel='hub' href='http://excitabyte.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Fight Corporate Censorship, Fight SOPA</title>
		<link>http://excitabyte.wordpress.com/2012/01/18/fight-corporate-censorship-fight-sopa/</link>
		<comments>http://excitabyte.wordpress.com/2012/01/18/fight-corporate-censorship-fight-sopa/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 15:09:55 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[censorship]]></category>
		<category><![CDATA[corporate censorship]]></category>
		<category><![CDATA[corporatism]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[sopa]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=414</guid>
		<description><![CDATA[Fight Corporate Censorship: Fight SOPA! Filed under: Uncategorized Tagged: censorship, corporate censorship, corporatism, internet, sopa<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=414&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="center"><a href="http://en.wikipedia.org/wiki/Wikipedia:SOPA_initiative/Learn_more" title="Fight SOPA"><img src="http://excitabyte.files.wordpress.com/2012/01/redacted.png?w=901" alt="[Redacted]" title="Redacted"   class="size-full wp-image-420" />
<p align="center">Fight Corporate Censorship: Fight SOPA!</p>
<p></a></p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/censorship/'>censorship</a>, <a href='http://excitabyte.wordpress.com/tag/corporate-censorship/'>corporate censorship</a>, <a href='http://excitabyte.wordpress.com/tag/corporatism/'>corporatism</a>, <a href='http://excitabyte.wordpress.com/tag/internet/'>internet</a>, <a href='http://excitabyte.wordpress.com/tag/sopa/'>sopa</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/414/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=414&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2012/01/18/fight-corporate-censorship-fight-sopa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>

		<media:content url="http://excitabyte.files.wordpress.com/2012/01/redacted.png" medium="image">
			<media:title type="html">Redacted</media:title>
		</media:content>
	</item>
		<item>
		<title>Meet blaze: C# without cruft!</title>
		<link>http://excitabyte.wordpress.com/2012/01/11/meet-blaze-c-without-cruft/</link>
		<comments>http://excitabyte.wordpress.com/2012/01/11/meet-blaze-c-without-cruft/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 22:45:35 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[.NET CLR]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Blaze]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[D-Flat]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=379</guid>
		<description><![CDATA[I&#8217;ve officially renamed SharpPad as &#8216;blaze&#8217;. Same scripting core host, but a new icon, new installer URL, and thanks to Brandon Berry, new features! For a limited time, you can download install directly from http://web.me.com/z.gramana/blaze/. You can still get the source from https://bitbucket.org/zgramana/sharpscript (although I&#8217;ll be moving the repository soon). NOTE: If you have already [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=379&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve officially renamed SharpPad as &#8216;blaze&#8217;. Same scripting core host, but a new icon, new installer URL, and thanks to <a href="http://b2berry.com/">Brandon Berry</a>, new features!</p>
<p>For a limited time, you can download install directly from <a href="http://web.me.com/z.gramana/blaze/">http://web.me.com/z.gramana/blaze/</a>.<br />
You can still get the source from <a href="https://bitbucket.org/zgramana/sharpscript">https://bitbucket.org/zgramana/sharpscript</a> (although I&#8217;ll be moving the repository soon).</p>
<p>NOTE: If you have already installed SharpPad, you&#8217;ll need to install blaze from the location above in order to received auto-updates.</p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/net-clr/'>.NET CLR</a>, <a href='http://excitabyte.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://excitabyte.wordpress.com/category/blaze/'>Blaze</a>, <a href='http://excitabyte.wordpress.com/category/c/'>C#</a>, <a href='http://excitabyte.wordpress.com/category/d-flat/'>D-Flat</a>, <a href='http://excitabyte.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/c/'>C#</a>, <a href='http://excitabyte.wordpress.com/tag/csharp/'>csharp</a>, <a href='http://excitabyte.wordpress.com/tag/scripting/'>scripting</a>, <a href='http://excitabyte.wordpress.com/tag/tools-2/'>tools</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/379/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=379&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2012/01/11/meet-blaze-c-without-cruft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>In Defense of &#8216;var&#8217;</title>
		<link>http://excitabyte.wordpress.com/2012/01/09/in-defense-of-var/</link>
		<comments>http://excitabyte.wordpress.com/2012/01/09/in-defense-of-var/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 20:13:44 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[var]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=377</guid>
		<description><![CDATA[The var keywords has unfairly earned a bad reputation. I see a lot of a hating on var, and don&#8217;t hear many people sticking up for it. If you don&#8217;t like var, or know someone who does, then this post is for you. My mom was born left-handed. The nuns at the Catholic school she [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=377&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <code>var</code> keywords has unfairly earned a bad reputation. I see a lot of a hating on var, and don&#8217;t hear many people sticking up for it. If you don&#8217;t like <code>var</code>, or know someone who does, then this post is for you.<br />
<span id="more-377"></span><br />
My mom was born left-handed. The nuns at the Catholic school she attended objected to this. Whenever she used her left hand, say to write with a pencil or cut paper with scissors, a nun would hit my mom&#8217;s left hand with a switch. They made her become right-handed, despite the fact that there is nothing inherently better about being dominant with either hand.  Food is not more nutritious when eaten with your right-hand. Words are not more expressive when written with your left-hand. The universe does not care which hand you use (even though it does seem to care about <a href="http://en.wikipedia.org/wiki/Chirality_%28chemistry%29">the handedness of matter</a>). Any benefit or detriment to being a &#8220;righty&#8221; derives from the fact that lots of other people are right-handed, or from other facts for which handedness merely stands as proxy (for example, brain hemisphere dominance in certain tasks). In fact, <a href="http://en.wikipedia.org/wiki/Handedness#Advantage_in_sports">being left-handed is considered an advantage in some socially valued activities</a> precisely <em>because</em> it is less common that being right-handed. Again, this slight advantage has nothing to do with being a &#8220;southpaw&#8221; per se. It wouldn&#8217;t be an advantage if 90% of people left-handed and only 10% right-handed.</p>
<p>Most of us never bother to consider all this, but once you do, it makes sense. Just like the universe doesn&#8217;t care whether you are left-handed or right-handed, the .NET compiler doesn&#8217;t care whether you use <code>var</code> or not (with two exceptions noted below).  It isn&#8217;t inherently worse or better. It&#8217;s utility depends on how you work best. For some, it cuts <em>against</em> the grain. For others, it cuts <em>with</em> the grain. If being a lefty is analogous to using var, then why are so many coders right-handed? I can&#8217;t say entirely, but I do believe it&#8217;s in part because nuns keep rapping the knuckles of developers when they opt to use it (ReSharper excluded).</p>
<p>I really only feel strongly about it because I think (a) it&#8217;s such a small thing that most people can&#8217;t be bothered to think much about it, and (b) as a result of (a), many people give too much credence to the opinions of &#8220;authorities&#8221; who weigh-in on the topic. I don&#8217;t want to rehash <a href="http://stackoverflow.com/questions/41479/use-of-var-keyword-in-c-sharp">prior discussions on the topic</a>, but I do want to distill down my view on the issue. Hopefully it will at least provide an entry point for some into even *having* a discussion. It&#8217;s <em>okay</em> to be use <code>var</code>. <a href="http://www.youtube.com/watch?v=GtkST5-ZFHw">It&#8217;s not your fault</a>.</p>
<p>So, I want to begin with laying out the standard arguments *against* using <code>var</code> (for anything other than anonymous types). I don&#8217;t want to attack straw men, here, so I&#8217;m trying to be accurate. Call me out if I miss my mark.</p>
<ol>
<li><strong><code>var</code> makes code less readable</strong>. To determine a variable&#8217;s type when using <code>var</code>, I&#8217;m required either to apply the same type inference logic that the compiler uses, or become dependent on an IDE&#8217;s Intellisense/autocomplete feature.</li>
<li><strong><code>var</code> makes refactoring more difficult</strong>. To change the type of every MyClass variable, I just need to <code>/MyClass/MyNewClass/g</code> and I&#8217;m done; whereas with <code>var</code> I will miss instances where the type was inferred from the return type of a method call.</li>
<li><a href="http://webcache.googleusercontent.com/search?sclient=psy-ab&amp;hl=en&amp;biw=1920&amp;bih=1085&amp;source=hp&amp;q=cache%3Ahttp%3A%2F%2Fwww.devx.com%2Fcodemag%2FArticle%2F37010%2F0%2Fpage%2F2&amp;pbx=1&amp;oq=cache%3Ahttp%3A%2F%2Fwww.devx.com%2Fcodemag%2FArticle%2F37010%2F0%2Fpage%2F2&amp;aq=f&amp;aqi=g4&amp;aql=&amp;gs_sm=e&amp;gs_upl=912l2084l0l2170l7l4l0l0l0l0l196l521l1.3l4l0"><strong><code>var</code> makes debugging more difficult</strong></a>. Because of (1), there is a category of bugs that won&#8217;t be caught until runtime, and where the exception will not intuitively relate to the underlying problem.</li>
</ol>
<p>Here are my counterarguments:</p>
<ol>
<li>
<p>This depends on what you consider &#8220;readable&#8221;, and in general I find the first line more &#8220;readable&#8221; (especially if you also do a fair amount of javascript):</p>
<p><pre class="brush: csharp;">
// Don't lie: which variable name can you spot faster?

// Focus my cognitive load only on the constructor call.
var lookupTable = new Dictionary&lt;String,Func&lt;Int,MyClass&gt;&gt;();

// Does the type declaration exactly match the constructor's class?
// It's going to take some mental effort to see.
Dictionary&lt;String,Func&lt;Int,MyClass&gt;&gt; lookupTable = new Dictionary&lt;String,Func&lt;Int,MyClass&gt;&gt;();

// I also find using interfaces clearer when using vars as well.
var instance = new MyRepository() as IRepository;
// Instead of:
IRepository instance = new MyRepository();
// This doesn't help me if MyRepository 
// actually implements IRepository&lt;T&gt;.
</pre></p>
<p>Considering nobody wants to type that loooong type name twice, most mortals will rely on autocomplete to avoid typing the entire thing anyways, so there is no great disadvantage there to using <code>var</code> in the first place. I also find myself wanting to start abbreviate/shorten longer, but more descriptive, type names when I don&#8217;t use <code>var</code> quite so much. It just gets fatiguing, and feels like my own code is &#8220;getting in my way&#8221;. I&#8217;ll take <code>ObservableCollection</code> over <code>ObsColl</code> when reading someone else&#8217;s code (or my own, six months later).<br />
In addition, I believe you <code>should</code> know the compiler&#8217;s type inference rules, and should be applying them every time you do an assignment&#8211;regardless of the style you&#8217;re opting for. If you can&#8217;t readily make out the type on the right side of assignment operator (I&#8217;m looking at you, overly-complicated LINQ expressions), then you have a code smell and probably need to refactor (e.g. to a <a href="http://msdn.microsoft.com/en-us/library/aa691356">method group</a>).</p>
</li>
<li>
<p>Take the following example:</p>
<p><pre class="brush: csharp;">
// Suppose:
IRepository instance = Repository.Create(typeof(MyClass));
// If I refactor MyRepository() to implement
// the generic interface, I now have to refactor
// my variable types as well. If I had just done:
var instance = Repository.Create(typeof(MyClass));
// Then I would be fine.
</pre></p>
<p>I argue that using <code>var</code> avoids a <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> violation. In fact, I actually <em>like</em> the fact that I can refactor a method return type without changing the variable declaration. Instead of the compiler complaining about the variable name not matching, it skips straight to all of the places where the new contract differs from the old contract. Declaring the variable type doesn&#8217;t avoid this, it just adds an additional compiler error noise. In general, I find the when using <code>var</code> when I don&#8217;t have to, I am paying closer attention to contracts and variable names&#8211;just the things I should be paying attention to.</p>
</li>
<li>
<p>I&#8217;m not going to argue too much against the example raised in the linked article. It&#8217;s an edge case for me, and in general, I find this to not really be a problem. My first question would be &#8220;why is the compiler think the result is a long instead of an int?&#8221; This would be the exact question that I would ask myself if I got a the error message at compile-time instead of run-time.<br />
However, consider the following function <code>f</code>:<br />
<pre class="brush: csharp;">
Func&lt;int&gt; f = ()=&gt;; 
{ 
    uint unsignedNumber = 42;
    int signedNumber = 10;
    var result = unsignedNumber * signedNumber;
    
    return result; 
};
</pre></p>
<p>Attempting to compile this snippet results in the following compiler errors:</p>
<blockquote><ul>
<li>Cannot convert lambda expression to delegate type &#8216;System.Func&#8217; because some of the return types in the block are not implicitly convertible to the delegate return type</li>
<li>Cannot implicitly convert type &#8216;long&#8217; to &#8216;int&#8217;. An explicit conversion exists (are you missing a cast?)</li>
</ul>
</blockquote>
<p>So, this <code>var</code> &#8220;fail&#8221; is even more of an edge case than presented originally.
</li>
<h5>Soooo&#8230;</h5>
<p>I am not  so much seeking to win converts over to using <code>var</code> as I hope people will begin to see this is as, at least, a style and preference issue&#8211;and not as an issue of right or wrong. Do I prefer <code>var</code>? You betcha! Do I look down on those who don&#8217;t? No, I get it. I&#8217;m just too lazy to do all that typing. Honestly, I&#8217;d rather save my finger strength for more coding. Or even&#8211;GASP!&#8211;blogging.
</ol>
<p>Oh, and the caveats mentioned above?</p>
<ul>
<li>If you are writing code against 2.0, then you obviously <em>can&#8217;t</em> use <code>var</code>. If you are going back in forth between say, 2.0 and 4.0, then I can absolutely appreciate wanting your fingers to remember just the one way.</li>
<li>If you are using anonymous types, or Linq, then you <em>have</em> to use <code>var</code>. Just like above, if you do a reasonable amount of either, then I can absolutely appreciate wanting your fingers to remember just the one way.</li>
</ul>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/c/'>C#</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/net/'>.NET</a>, <a href='http://excitabyte.wordpress.com/tag/c/'>C#</a>, <a href='http://excitabyte.wordpress.com/tag/c-sharp/'>c-sharp</a>, <a href='http://excitabyte.wordpress.com/tag/csharp/'>csharp</a>, <a href='http://excitabyte.wordpress.com/tag/dotnet/'>dotnet</a>, <a href='http://excitabyte.wordpress.com/tag/var/'>var</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/377/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=377&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2012/01/09/in-defense-of-var/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Forking Github Repos on Win32</title>
		<link>http://excitabyte.wordpress.com/2011/09/07/forking-github-repos-on-win32/</link>
		<comments>http://excitabyte.wordpress.com/2011/09/07/forking-github-repos-on-win32/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 20:56:32 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Source Control]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[PCG]]></category>
		<category><![CDATA[source control]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=361</guid>
		<description><![CDATA[I’ll be upfront: I’m a Mercurial guy. But sometimes I have no choice but to use git. That’s often a painful proposition on Win32, especially when using github. Github’s advice on forking a repository flat out does not work for me, so I follow this slightly modified process instead.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=361&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be upfront: I&#8217;m a <a href="http://mercurial.selenic.com/" title="Mercurial home page">Mercurial</a> guy. But sometimes I have no choice but to use <a href="http://git-scm.com/" title="git home page">git</a>. That&#8217;s often <a href="http://stackoverflow.com/questions/783906/git-under-windows-msys-or-cygwin">a painful proposition on Win32</a>, especially when using <a href="http://github.com" title="github">github</a>. <a href="http://help.github.com/fork-a-repo/" title="Fork a Repository">Github&#8217;s advice on forking a repository</a> flat out does not work for me, so I follow this slightly modified process instead.<span id="more-361"></span></p>
<p>Perhaps I just have an outdated <a href="http://code.google.com/p/msysgit/" title="msysgit homepage">msysgit</a> installation, perhaps it&#8217;s just a limitation of running git on win32, or perhaps my gitfu is just not l33t enough. Who knows. After many fails, though, this sequence of <code>git bash</code> commands is the only thing that works for me:</p>
<p><pre class="brush: bash;">
git clone https://github.com/&lt;your_username&gt;/&lt;child_repo_name&gt;.git
cd &lt;child_repo_name&gt;
git remote add upstream https://github.com/&lt;parent_repo_owner_username&gt;/&lt;parent_repo_name&gt;.git
git fetch upstream
git merge upstream/master
git push origin master
</pre></p>
<p>Using the git protocol over ssh seems to be a no-go, so I&#8217;m using HTTPS instead.  Hopefully this solution works for you too.</p>
<p>If you&#8217;re on <code>msysgit</code>, and are having trouble working with github, I feel you.  If not, or if you have a better solution, please post a comment and share.</p>
<p>Happy forking!</p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/source-control/'>Source Control</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/git/'>git</a>, <a href='http://excitabyte.wordpress.com/tag/github/'>github</a>, <a href='http://excitabyte.wordpress.com/tag/pcg/'>PCG</a>, <a href='http://excitabyte.wordpress.com/tag/source-control-2/'>source control</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/361/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=361&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2011/09/07/forking-github-repos-on-win32/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Wrap Any Class in Dynamic Goodness</title>
		<link>http://excitabyte.wordpress.com/2011/08/11/wrap-any-class-in-dynamic-goodness/</link>
		<comments>http://excitabyte.wordpress.com/2011/08/11/wrap-any-class-in-dynamic-goodness/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 02:41:05 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[DLR]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[Language Dynamicism]]></category>
		<category><![CDATA[PCG]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=326</guid>
		<description><![CDATA[Easy, no-fuss decoration without class explosion? What if we can prevent that? This is where a <i>generic</i> wrapper class comes in handy. With one class, we can wrap not just one class, but any member of <i>set</i> of classes.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=326&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I use the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a> like it&#8217;s going out of style. Not really. I would, though, if it didn&#8217;t tend to lead to class explosion. Instead of <a href="http://martinfowler.com/eaaDev/PresentationModel.html">using it in a broad way</a>, I tend to reach for it in a couple of common scenarios:</p>
<ol>
<li>when someone else&#8217;s object doesn&#8217;t do what I want it to, and isn&#8217;t <a href="http://en.wikipedia.org/wiki/Open/closed_principle">open for extension</a>, or</li>
<li>when I want to pass an object to a method that wouldn&#8217;t accept the object otherwise.</li>
</ol>
<p>However, decoration can be tedious, can violate the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY principle</a>, and can lead to lots of little wrapper classes lying around that just clutter a project up. What if we can prevent that?<span id="more-326"></span>This is where a <i>generic</i> <code>Wrapper&lt;T&gt;</code> class would come in really handy. With one class, we could wrap not just one class, but any member of <i>set</i> of classes. While this is an interesting idea, we can anticipate some limitations. For one, we would be giving the same new capabilities to all of the wrapped classes. Unless we&#8217;re implementing a specific interface, that&#8217;s not something we need to do very often. We want to be able to add new members when we want to, and without having to create a new decorator class. The alternatives, like writing a ton of reflection code or emitting bytecode, introduce design-time and run-time overhead that reduce the potential convenience of our generic wrapper class. However, using .NET 4.0&#8242;s support for <a href="http://en.wikipedia.org/wiki/Dynamic_Language_Runtime">the Dynamic Language Runtime</a> offers the missing piece of our puzzle.</p>
<p>The result: our <code>Dynamic&lt;T&gt;</code> class, presented below.  The code shows an example of how you might choose to implement your own generic dynamic wrapper class. It uses reflection in some smart ways to give us the benefit of strong type-iness, while at the same time allowing us to go buck wild adding new properties and methods at runtime with reckless abandon. With just a little extra work, you can even implement <code>ISerializable</code>. <a href="http://www.youtube.com/watch?v=h121VfLPsDo">Woo wooooo</a>! </p>
<p>So, how does that help us with our two scenarios from before? Well, it can come in handy for Scenario 1 when you want to, say, serialize <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx">a class that isn&#8217;t marked with [Serializable]</a>. It&#8217;s also handy for Scenario 2, where we want wrap an interface implementation around an object that doesn&#8217;t already support it.  This gives us the ability to pass our original object to other methods that wouldn&#8217;t otherwise take them. In the example below, we&#8217;re writing a wrapper that allows our original object to comply with the DynamicObject contract. So, with that in mind, let&#8217;s get our code on:</p>
<p><pre class="brush: csharp;">
// Copyright:     (C) 2011 by Zachary Gramana
// Author:        Zachary Gramana
// Version:       0.1
// Description:   Wraps any class inside of a DynamicObject.
// StartedOn:     7/20/2011
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;

namespace Utility.Types
{
    /// &lt;summary&gt;
    /// Wraps any object in a DynamicObject, but in a strongly-typed way.
    /// It also logs usage of the object to standard output.
    /// 
    /// Running:
    ///     dynamic item = new Dynamic&lt;String&gt;(&quot;Jabberwocky&quot;);
    ///     item = new Dynamic&lt;AppDomain&gt;(AppDomain.CurrentDomain);
    ///     item.SetData(&quot;Foo&quot;, &quot;Bar&quot;);
    ///     item.GetData(&quot;Foo&quot;);
    ///     item.Foo = &quot;Bar&quot;;
    ///     var bar = item.Foo;
    /// 
    /// Outputs:
    ///     Dynamic's Inherited Properties:
    ///             Chars
    ///             Length
    /// 
    ///     Dynamic's Inherited Properties:
    ///             DomainManager
    ///             CurrentDomain
    ///             Evidence
    ///             FriendlyName
    ///             BaseDirectory
    ///             RelativeSearchPath
    ///             ShadowCopyFiles
    ///             ActivationContext
    ///             ApplicationIdentity
    ///             ApplicationTrust
    ///             DynamicDirectory
    ///             SetupInformation
    ///             PermissionSet
    ///             IsFullyTrusted
    ///             IsHomogenous
    ///             Id
    ///             MonitoringIsEnabled
    ///             MonitoringTotalProcessorTime
    ///             MonitoringTotalAllocatedMemorySize
    ///             MonitoringSurvivedMemorySize
    ///             MonitoringSurvivedProcessMemorySize
    /// 
    /// Results:
    ///     Invoking instance.SetData() returned '(null)'
    /// 
    /// Results:
    ///     Invoking instance.GetData() returned 'Bar'
    /// 
    /// Results:
    ///     Setting instance.Foo = Bar
    /// 
    /// Results:
    ///     Getting instance.Foo returned 'Bar'
    /// 
    /// &lt;/summary&gt;
    public class Dynamic&lt;T&gt; : DynamicObject
    {
        private static readonly Dictionary _propertyCache;
        private        readonly T          _instance;
        private        readonly Dictionary _propertyBag;
        
        /// &lt;summary&gt;
        /// Our type constructor. This populates our lookup store with
        /// all of the property information we need about the object
        /// we are wrapping. This runs just once, the first time
        /// we make an instance of the a particular type.
        /// &lt;/summary&gt;
        static Dynamic()
        {
            _propertyCache = typeof(T)
                .GetProperties()
                .ToDictionary(
                    k =&gt; k.Name, 
                    k =&gt; (Object)k
                   );

            Console.WriteLine(&quot;\r\nDynamic's Inherited Properties:&quot;, typeof(T).Name);
            foreach (var prop in _propertyCache) 
            {
                Console.WriteLine(&quot;\t&quot; + prop.Key);
            }
        }
        
        /// &lt;summary&gt;
        /// Our instance constructor.
        /// &lt;/summary&gt;
        /// The object we are wrapping.
        public Dynamic(T instance)
        {
            _instance = instance;
            _propertyBag = new Dictionary(StringComparer.CurrentCulture);
            
            // Log this action.
            Console.WriteLine(&quot;\r\nCreated new {0} wrapper object.&quot;, this.GetType().Name.TrimEnd(new[] {'`','1'}), this.GetType().GetGenericArguments()[0].Name);
        }
        
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            Boolean value;

            Object prop;
            value = _propertyCache.TryGetValue(binder.Name, out prop);

            if (value)
            {
                result = ((PropertyInfo) prop).GetValue(_instance, null);
                value = true;
            }
            else
            {
                value = _propertyBag.TryGetValue(binder.Name, out result);
            }
            
            // Log this action.
            Console.WriteLine(&quot;\r\nResults:\r\n\tGetting instance.{0} returned '{1}'&quot;, binder.Name, result ?? &quot;(null)&quot;);
            
            return value;
        }

        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            Object prop;
            var foundProp = _propertyCache.TryGetValue(binder.Name, out prop);
            
            if (foundProp)
            {
                ((PropertyInfo) prop).SetValue(_instance, value, null);
            }
            else
            {
                _propertyBag[binder.Name] = value;
            }
            
            // Log this action.
            Console.WriteLine(&quot;\r\nResults:\r\n\tSetting instance.{0} = {1}&quot;, binder.Name, value ?? &quot;(null)&quot;);

            // You can always add a value to a dictionary,
            // so this method always returns true.
            return true;
        }
        
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            // Use reflection to get the method info.
            var method = typeof(T)
                .GetMethod(
                    binder.Name, 
                    args.Select(a =&gt; a.GetType())
                        .ToArray()
               );
            
            if (method == null) 
            {
                result = null;
                return false;
            }
            
            result = method.Invoke(_instance, args);

            // Log this action.
            Console.WriteLine(&quot;\r\nResults:\r\n\tInvoking instance.{0}() returned '{1}'&quot;, method.Name, result ?? &quot;(null)&quot;);
            
            // If we didn't throw an exception, we succeeded.
            return true;
        }
        
        public T GetInstance()
        {
            return _instance;
        }
    }
}
</pre></p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/c/'>C#</a>, <a href='http://excitabyte.wordpress.com/category/design-patterns/'>Design Patterns</a>, <a href='http://excitabyte.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/net/'>.NET</a>, <a href='http://excitabyte.wordpress.com/tag/c/'>C#</a>, <a href='http://excitabyte.wordpress.com/tag/design-patterns/'>Design Patterns</a>, <a href='http://excitabyte.wordpress.com/tag/dlr/'>DLR</a>, <a href='http://excitabyte.wordpress.com/tag/generics/'>Generics</a>, <a href='http://excitabyte.wordpress.com/tag/language-dynamicism/'>Language Dynamicism</a>, <a href='http://excitabyte.wordpress.com/tag/pcg/'>PCG</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=326&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2011/08/11/wrap-any-class-in-dynamic-goodness/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Towards Better Graph Loading Via Conditional Types</title>
		<link>http://excitabyte.wordpress.com/2011/07/13/towards-better-graph-loading-via-conditional-types/</link>
		<comments>http://excitabyte.wordpress.com/2011/07/13/towards-better-graph-loading-via-conditional-types/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 21:01:20 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Graph Management]]></category>
		<category><![CDATA[JavaScript/EcmaScript]]></category>
		<category><![CDATA[Runtime]]></category>
		<category><![CDATA[graph loading]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json-schema]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=316</guid>
		<description><![CDATA[One of my pet peeves is the cruft we often add to our objects to support graph loading. For example, we might create a special "lazy loading" type wrapper (e.g. Lazy) or we might create two independent fields that represent, in effect, the same thing (e.g. Employee MyManager and Guid MyManager_ID). Neither is clean, and each has its issues. I want something better, like this.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=316&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of my pet peeves is the cruft we often add to our objects to support graph loading. For example, we might create a special &#8220;lazy loading&#8221; type wrapper (e.g. Lazy) or we might create two independent fields that represent, in effect, the same thing (e.g. Employee MyManager and Guid MyManager_ID). Neither is clean, and each has its issues. I want something better.<span id="more-316"></span></p>
<p>JSON-Schema lets us do some cool things, like allowing more than one type to be valid for a given property.  For example, I could allow a property to take, say, either a string or an integer. This is called a union type. Cool enough.  But how could this help us with graph loading?</p>
<p>Consider something like this:<br />
<pre class="brush: jscript;">
   &quot;properties&quot;:{
       &quot;MyManager&quot;:{
           &quot;title&quot;:&quot;MyManager&quot;,
           &quot;type&quot;:[{&quot;type&quot;:&quot;string&quot;,&quot;pattern&quot;,&quot;(\w|-){22,24}&quot;},&quot;object&quot;],
       }
   }
</pre><br />
It&#8217;s subtle, but powerful.  If accountObj.MyManager is a string type, then we can assume the string is a base64-encoded guid and use that ID to load the object.  Once we load the object via another ajax call, we replace the id with the object. We don&#8217;t loose data, since the object would be exposing that id as a property (or at least holding it internally). The only downside is we loose our ability to provide a type schema for the MyManager property once the object is loaded.</p>
<p>What I *really* want is the ability to do:<br />
<pre class="brush: jscript;">
   &quot;properties&quot;:{
       &quot;MyManager&quot;:{
           &quot;title&quot;:&quot;MyManager&quot;,
           &quot;type&quot;:[&quot;http://localhost/schemas/models/employee#/id&quot;,&quot;object&quot;],
       }
   }
</pre><br />
This would allow us to know that the value will be a base64 guid string, but that the loaded object is an employee model. JSON-Schema doesn&#8217;t yet allow this yet.  Union types cannot include these kind of external references.  But the draft standard is evolving and can be extended, as can our implementations of it.  The syntax used above *does* however conform to the newly submitted <a href="http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-00">IETF JSON Pointer draft standard</a>, which is an spinoff of the <a href="http://groups.google.com/group/json-schema">JSON-Schema group</a>.</p>
<p>Either way, it&#8217;s a handy trick to add in your collection.</p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/graph-management/'>Graph Management</a>, <a href='http://excitabyte.wordpress.com/category/javascriptecmascript/'>JavaScript/EcmaScript</a>, <a href='http://excitabyte.wordpress.com/category/runtime/'>Runtime</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/graph-loading/'>graph loading</a>, <a href='http://excitabyte.wordpress.com/tag/javascript/'>javascript</a>, <a href='http://excitabyte.wordpress.com/tag/json/'>json</a>, <a href='http://excitabyte.wordpress.com/tag/json-schema/'>json-schema</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=316&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2011/07/13/towards-better-graph-loading-via-conditional-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>A Handy MSDN Bookmarklet</title>
		<link>http://excitabyte.wordpress.com/2011/04/12/a-handy-msdn-bookmarklet/</link>
		<comments>http://excitabyte.wordpress.com/2011/04/12/a-handy-msdn-bookmarklet/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 23:04:06 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=289</guid>
		<description><![CDATA[If you&#8217;re like me, you don&#8217;t do all of your coding in Visual Studio.  That&#8217;s when you start to miss the convenience of just hitting F1 to bring up the MSDN documentation for a specific class. To bring that simplicity to your browser, just paste the following into the URL field of a manually created [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=289&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like me, you don&#8217;t do all of your coding in Visual Studio.  That&#8217;s when you start to miss the convenience of just hitting F1 to bring up the MSDN documentation for a specific class.</p>
<p>To bring that simplicity to your browser, just paste the following into the URL field of a manually created bookmark:</p>
<p><code>javascript:(function(){c=prompt("Enter the fully-qualified name of a class, method, property, etc.:","System.Object");window.location="http://msdn.microsoft.com/en-us/library/"+c+"(v=VS.100).aspx"}());</code></p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://excitabyte.wordpress.com/category/msdn/'>MSDN</a>, <a href='http://excitabyte.wordpress.com/category/tools/'>Tools</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=289&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2011/04/12/a-handy-msdn-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Defaulting on Orchard CMS</title>
		<link>http://excitabyte.wordpress.com/2011/04/04/262/</link>
		<comments>http://excitabyte.wordpress.com/2011/04/04/262/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 14:23:07 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Orchard CMS]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC3]]></category>
		<category><![CDATA[Orchard]]></category>
		<category><![CDATA[OrchardCMS]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=262</guid>
		<description><![CDATA[When creating a new Orchard module, I needed to set the default value for an integer.  The thing is, you can't do it in your model class like you would normally do.  Property getter/setters are just getting/setting the underlying record, and the constructor runs before the record object has been created.  What now?<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=262&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When creating a new Orchard module, I needed to set the default value for an integer.  The thing is, you can&#8217;t do it in your model class like you would normally do.  Property getter/setters are just getting/setting the underlying record, and the constructor runs before the record object has been created.  What now?</p>
<p><span id="more-262"></span></p>
<p>The intrepid code will most likely try the <code>DefaultValueAttribute</code> next, and end up with something like.</p>
<p><pre class="brush: csharp;">
[DefaultValue(5)]
public int FavoriteNum
{
    get { return Record.FavoriteNum; }
    set { Record.FavoriteNum = value; }
}
</pre></p>
<p>And, regrettably, this doesn&#8217;t work.</p>
<p>Our intrepid coder now scours the documentation and discovers the <code>.WithDefault()</code> method buried in the migrations code:</p>
<p><pre class="brush: csharp;">
        public int Create()
        {
            SchemaBuilder.CreateTable(&quot;MyPartRecord&quot;, table =&gt; table
                    .ContentPartRecord()
                    .Column(&quot;FavoriteNum&quot;, c =&gt; c.NotNull().WithDefault(5))
                );
        }
</pre></p>
<p>Euphoria runs high, as the database <em>does indeed</em> construct the proper default constraint. Woo hoo!  Except that Orchard doesn&#8217;t pass null to this value, it always gets 0. The wave of euphoria comes crashing down on the rocky shores of reality. Sad trombones lament your misfortune.</p>
<p>Don&#8217;t worry, you still have options. If your model class inherits from a class derived from <code>ContentPart&lt;TPartRecord&gt;</code>, all you need to do is initialize your value in <code>TPartRecord</code>&#8216;s constructor. For example, assume <code>MyPart</code> inherits from <code>ContentPart</code>:</p>
<p><pre class="brush: csharp;">
public class MyPart : ContentPart&lt;MyPartRecord&gt; {
	public int FavoriteNum {
		get { return Record.FavoriteNum; }
		set { Record.FavoriteNum = value;}
	}
}

public class MyPartRecord : ContentPartRecord {
	public MyPartRecord() { FavoriteNum = 5; }
	public virtual int FavoriteNum { get; set; }
}
</pre></p>
<p>But what if your model class inherits from <code>ContentPart </code>instead?  The <code>ContentPart</code>class lives in the Orchard framework, and so we aren&#8217;t able to use the above technique.  If you&#8217;ve been down this road, then you know it feels like a dead-end.  We&#8217;re in luck, though.  Our solution comes via the event hooks that are exposed by deriving a class from <code>ContentHandler</code>. In particular, we need to pass your default-value-setting code to the <code>OnInitializing</code> method. Here is an example part handler class that finally does what we&#8217;ve been trying to do:</p>
<p><pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Contrib.MyModule.Models;

namespace Contrib.MyModule.Handlers
{
    public class MyPartHandler : ContentHandler
    {
        public MyPartHandler(IRepository repository)
        {
            Filters.Add(StorageFilter.For(repository));
            OnInitializing((context, part) =&gt; {
                part.FavoriteNum = 32;
              });
        }
    }
}
</pre></p>
<p>And there was much rejoicing.  Happy coding!</p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/orchard-cms/'>Orchard CMS</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/net/'>.NET</a>, <a href='http://excitabyte.wordpress.com/tag/c/'>C#</a>, <a href='http://excitabyte.wordpress.com/tag/mvc3/'>MVC3</a>, <a href='http://excitabyte.wordpress.com/tag/orchard/'>Orchard</a>, <a href='http://excitabyte.wordpress.com/tag/orchardcms/'>OrchardCMS</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/262/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=262&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2011/04/04/262/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Dangerous .NET CLR Quirk Lurks In Unfiltered Generic Methods</title>
		<link>http://excitabyte.wordpress.com/2011/03/02/watch-the-net-clr-fail-right-before-your-eyes/</link>
		<comments>http://excitabyte.wordpress.com/2011/03/02/watch-the-net-clr-fail-right-before-your-eyes/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 19:37:58 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[.NET CLR]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Runtime]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[JIT]]></category>
		<category><![CDATA[language design]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=246</guid>
		<description><![CDATA[Step right up! Step right up! Come inside and watch in horror as our sample C# code compiles, runs, and spectacularly fails right before your unbelieving eyes.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=246&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Step right up! Step right up! Come inside and watch in horror as our sample C# code compiles, runs, and spectacularly fails right before your unbelieving eyes.</p>
<p><span id="more-246"></span></p>
<p>This sample code will compile, and run, and fail oh-so-epically:</p>
<p><pre class="brush: csharp;">
using System;

namespace VirtualSpike
{

    class Program
    {
        // Internal static field.
        private static dynamic _singleton;
    
        // Singleton manager.
        public static dynamic YourFateSingleton&lt;T&gt;(T myT)
        {
            if (myT == null)
            {
                _singleton = default(T);
                return _singleton;
            }
            else
            {
                return _singleton;
            }
        }
        
        static void Main(string[] args)
        {
            var fate = Program.YourFateSingleton(DateTime.Now);
            Console.WriteLine(&quot;You will become fabulously rich at&quot;);
            Console.WriteLine(&quot;this exact date and time: {0}&quot;, fate);
        }
    }
}
</pre></p>
<p><strong>Can you figure out why?</strong> (I&#8217;ll give you a hint: read section 12.9.4.3 of Jeffrey Richter&#8217;s &#8220;CLR via C#&#8221;)</p>
<p>&nbsp;</p>
<p>(spoiler ahead)</p>
<p>&nbsp;</p>
<p>If you suspect that the answer has something to do with the way the CLR implements generics, then you would be right. The CLR gives us the ability to filter our type variable, <code>T</code>, so that only specific set of types are eligible to become <code>T</code>.  This is very important feature of the CLR&#8217;s generic implementation, and sets it apart from other languages.</p>
<p>When a generic method is not provided with a filter, both value types <strong>and</strong> reference types are permissible as values for <code>T</code>.  This fact allows us to pass a <code>DateTime</code> object, which is a value type (viz., a <code>struct</code>), to our singleton&#8217;s factory method.  Unfortunately for us, even though the runtime will <strong>never</strong> evaluate the <code>null</code> check, the C# compiler will not even so much as throw up a warning or an information message.  As a result, our singleton will (silently) never get initialized for our <code>DateTime</code> parameter.</p>
<p> Hopefully, someday, the C# compiler team will break on the same error as it does for trying to set <code>myT</code> to null, or at least return a warning. Until then, be sure to set the filter to <code>where T: class</code> or avoid <code>null</code> checks in unfiltered generic methods.</p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/net-clr/'>.NET CLR</a>, <a href='http://excitabyte.wordpress.com/category/optimization/'>Optimization</a>, <a href='http://excitabyte.wordpress.com/category/runtime/'>Runtime</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/net/'>.NET</a>, <a href='http://excitabyte.wordpress.com/tag/c/'>C#</a>, <a href='http://excitabyte.wordpress.com/tag/clr/'>CLR</a>, <a href='http://excitabyte.wordpress.com/tag/compiler/'>compiler</a>, <a href='http://excitabyte.wordpress.com/tag/dotnet/'>dotnet</a>, <a href='http://excitabyte.wordpress.com/tag/generics/'>Generics</a>, <a href='http://excitabyte.wordpress.com/tag/jit/'>JIT</a>, <a href='http://excitabyte.wordpress.com/tag/language-design/'>language design</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/246/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=246&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2011/03/02/watch-the-net-clr-fail-right-before-your-eyes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Part II: Spawning Threads Using Selectors With Multiple Parameters</title>
		<link>http://excitabyte.wordpress.com/2010/05/18/part-ii-spawning-threads-using-selectors-with-multiple-parameters/</link>
		<comments>http://excitabyte.wordpress.com/2010/05/18/part-ii-spawning-threads-using-selectors-with-multiple-parameters/#comments</comments>
		<pubDate>Tue, 18 May 2010 17:38:28 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Cocoa Libraries]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Threading]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[NSInvocation]]></category>
		<category><![CDATA[NSThread]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=208</guid>
		<description><![CDATA[In Part I, we introduced a method that emulates the Apple-supplied convenience method performSelectorInBackground:withObject:, but which adds support for selectors that take multiple objects as arguments. We saw the power of NSInvocation objects, but also saw how they were a bit cumbersome to use on a routine basis. Our solution gave us what we wanted [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=208&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://excitabyte.wordpress.com/2009/07/07/spawning-threads-using-selectors-with-multiple-parameters/">In Part I</a>, we introduced a method that emulates the Apple-supplied convenience method <code>performSelectorInBackground:withObject:</code>, but which adds support for selectors that take multiple objects as arguments.  We saw the power of NSInvocation objects, but also saw how they were a bit cumbersome to use on a routine basis.  Our solution gave us what we wanted by allowing us to pass in an array of objects to be used, along with a multi-parameter selector, to invoke an arbitrary method on a background thread (or on the main thread).</p>
<p>This solution is a great step forward when we need to invoke something like <code>[myObj setCharacter:@"The Doctor" currentActor:@"Matt Smith"]</code>.  But what if we have a bunch of methods that don&#8217;t take objects?  Wrapping them all in NSValues begins to really litter-up the code, and is frankly a bit tedious.  And what if one want to invoke something like <code>[myObj setCharacter:@"The Doctor" favoriteActors:@"Tom Baker", @"David Tennant", @"Matt Smith"]</code>?  There has to be a cleaner way, right? Behold! There is, and the answer lies in the somewhat obscure-ish <a href="http://developer.apple.com/mac/library/qa/qa2005/qa1405.html">va_arg macro</a>.  Now we can save the world from our unwieldy code. <i>Allons-y</i>!</p>
<p><span id="more-208"></span></p>
<p>We are already familiar with methods that take a <code>nil</code>-terminated list of arguments.  For example, NSArray offers its <code>arrayWithObjects:</code> method.  We know that we can pass a list of comma-separated objects to this method, so long as the list ends with a <code>nil</code>.</p>
<p>  Hmm&#8230;wouldn&#8217;t it be handy if we could do the same thing with our own method?  Enter the <code>va_list</code>.</p>
<p>Let&#8217;s begin with our method&#8217;s definition in our header file.  We need some way of letting the compiler know that <i>we don&#8217;t know</i> just how many arguments arguments to expect ahead of time. Apple&#8217;s documentation for NSArray use the ellipsis, that is three periods in a row without spaces.  That&#8217;s not just a mere convention that prose writers use. It&#8217;s actually a symbol that the compiler understands to mean a <em>nil-terminated list</em>. <em>Molto bene</em>! Now our method definition looks something like:<br />
<pre class="brush: cpp;">
- (void)performSelector:(SEL)aSelector withContext:(void *)context, ... ;
</pre></p>
<p>To invoke a method on another thread, we went from:</p>
<ul>
<li><code>[myObj performSelector:@selector(setActorCount:role:) withContext:[NSArray arrayWithObjects: [NSValue valueWithBytes:&amp;doctorCount objCType:@encode(int)], @"The Doctor", nil]]</code>    (yikes!)</li>
</ul>
<p>to:</p>
<ul>
<li><code>[myObj performSelector:@selector(setActorCount:role:) withContext:(int *)doctorCount, @"The Doctor", nil]</code></li>
</ul>
<p>That&#8217;s more like it! Notice how our simplified method signature is also much easier to deal with when debugging?  That alone makes the change worth while.  So now that we&#8217;ve settled that, let&#8217;s take a look at our revised method&#8217;s implementation:
</p>
<p><pre class="brush: cpp;">
- (void)performSelector:(SEL)aSelector
			 withValues:(void *)context, ...
{	// See if we were even passed any context.
	if (context)
	{
		// We'll need an NSInvocation, since it lets us define arguments
		// for multiple parameters.
		NSMethodSignature *theSignature = [self methodSignatureForSelector:aSelector];
		NSInvocation *theInvocation = [NSInvocation invocationWithMethodSignature:theSignature];
		[theInvocation retainArguments];

		// Now for the real automagic fun!  We will loop through our arugment list,
		// and match up each parameter with the corresponding index value.

		// Since Objective-C actually converts messages into C methods:
		NSUInteger argumentCount = [theSignature numberOfArguments] - 2;

		[theInvocation setTarget:self];			// There's our index 0.
		[theInvocation setSelector:aSelector];	// There's our index 1.

		// Use the va_* macros to retrieve the arguments.
		va_list arguments;

		// Tell it where the optional args start.
		// Since the first parameter, the selector
		// Isn't optional, tell it to start with 'context'.
		va_start (arguments, context);

		// Now for arguments 2+
		NSUInteger i, count = argumentCount;
		void* currentValue = context;
		for (i = 0; i &lt; count; i++)
		{
			// If we run out of arguments, then we pass nil
			// to the remaining parameters.
			[theInvocation setArgument:&amp;currentValue atIndex:(i + 2)]; // The +2 represents self and cmd offsets
			currentValue = va_arg(arguments, void*); // Read the next argument in the list.

			// We should also handle the case where we have
			// *more* arguments than parameters.  This will
			// let us cover cases where we are invoking
			// other variadic methods (like arrayWithObjects:).
		}

		// Dispose of our C byte-array.
		va_end (arguments);

		// That's it! (For configuring our NSInvocation).
		// In this example, we are going to invoke all
		// methods on a custom worker thread.
		NSThread *customWorkerThread = [EBCustomThread sharedCustomThread];

		// Invoke on our custom worker thread.
		[theInvocation performSelector:@selector(invoke) onThread:customWorkerThread withObject:nil waitUntilDone:NO];

		// Our NSInvocation is already autoreleased, so we're done.

	} else {
		// Since we were not given any context arguments,
		// just do a non-blocking invocation on a background thread.
		// We really would want to check to see that the selector
		// is valid, takes no arguments, etc., but that is left
		// as an exercise for the reader.
		[self performSelectorInBackground:aSelector withObject:nil];
	} 
}
</pre></p>
<p>So there you have it. </p>
<p>
  <b>[Update: Doug, the lead over at the the <a href="http://zoosk.com">Zoosk.com</a> mobile dev, has taken the time to add <a href="https://github.com/Zoosk/ZSFoundation/blob/master/Categories/NSObject+ZSFoundation.m">the above method as a category on NSObject</a> as part of the their <a href="https://github.com/Zoosk/ZSFoundation">very useful ZSFoundation library</a>. Big thanks to Doug and his team for sharing!]</b>
</p>
<p>If you are interested in more threading tricks, check out these other fine articles:</p>
<ul>
<li>Matt Gallagher&#8217;s article <a href="http://cocoawithlove.com/2008/03/construct-nsinvocation-for-any-message.html">&#8220;Construct an NSInvocation for any message, just by sending&#8221;</a>.</li>
<li>Dave Dribbin&#8217;s blog post &#8220;<a title="Invoke on Main thread" href="http://www.dribin.org/dave/blog/archives/2008/05/22/invoke_on_main_thread/">Invoke on Main Thread</a>&#8220;</li>
<li>Gabriel Handford&#8217;s post &#8220;<a title="Invoking Forward" href="http://rel.me/2009/05/22/nsinvocation-nsproxy-forwardinvocatio/">Invoking Forward</a>.&#8221;</li>
</ul>
<p>Happy threading!</p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/cocoa-libraries/'>Cocoa Libraries</a>, <a href='http://excitabyte.wordpress.com/category/optimization/'>Optimization</a>, <a href='http://excitabyte.wordpress.com/category/threading/'>Threading</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/cocoa/'>Cocoa</a>, <a href='http://excitabyte.wordpress.com/tag/iphone/'>iPhone</a>, <a href='http://excitabyte.wordpress.com/tag/nsinvocation/'>NSInvocation</a>, <a href='http://excitabyte.wordpress.com/tag/nsthread/'>NSThread</a>, <a href='http://excitabyte.wordpress.com/tag/objective-c/'>Objective-C</a>, <a href='http://excitabyte.wordpress.com/tag/threading/'>Threading</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=208&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2010/05/18/part-ii-spawning-threads-using-selectors-with-multiple-parameters/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>The Names of Fonts Available on iPhone OS</title>
		<link>http://excitabyte.wordpress.com/2010/03/24/the-font-family-names-available-on-iphone-os/</link>
		<comments>http://excitabyte.wordpress.com/2010/03/24/the-font-family-names-available-on-iphone-os/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 22:47:54 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Cocoa Libraries]]></category>
		<category><![CDATA[User Experience]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[UIFont]]></category>
		<category><![CDATA[UILabel]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=181</guid>
		<description><![CDATA[Interface Builder is great. It&#8217;s an Apple-y app the lets you build your own Apple-y apps. It&#8217;s all so much Apple-y goodness. Well, maybe even too much goodness. Say you want to change the font family for your UILabel. Maybe you like the Helvetica. Or maybe you like the Arial.  So off you go to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=181&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Interface Builder is great.  It&#8217;s an Apple-y app the lets you build your own Apple-y apps.  It&#8217;s all so much Apple-y goodness.  Well, maybe even <em>too</em> much goodness.  Say you want to change the font family for your UILabel.  Maybe you <a href="http://www.ms-studio.com/articles.html">like</a> the <a href="http://www.mimeartist.com/helvetica/">Helvetica</a>.  Or maybe you like the <a href="http://www.threadless.com/submission/61387/I_Like_Arial_Black">Arial</a>.  So off you go to the Attributes Inspector and dutifully click on the Font attribute.  POP!  The familiar ol&#8217; standard OS X font selection dialog window springs up in front of you&#8230;with all your workstation&#8217;s installed and active fonts.  Here&#8217;s the catch: the vast majority of those fonts will not be available on your iPhone or iPod Touch application. <a href="http://www.hulu.com/watch/19280/saturday-night-live-debbie-downer-birthday-party">What a downer</a>. But we can at least sort this out easily enough.<span id="more-181"></span></p>
<p>For the impatient among us, I&#8217;ll just list out the fonts available as of iPhone OS version 3.1.3 below.  If you would rather learn how to fish, as it were, then here&#8217;s a quick method of determining the available font names yourself:</p>
<p><code><pre class="brush: cpp;">
NSArray *fontFamilyNames = [UIFont familyNames];

for (NSString *familyName in fontFamilyNames)
{
	NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
	for (NSString *name in fontNames)
	{
		// Do your font-y stuff here.
		NSLog(&quot;%@&quot;, name);
	}
}
</pre></p>
<p></code></p>
<p>Nice, eh?</p>
<p>Now, as promised, the font names available on the iPhone OS on version 3.1.3, organized by family:</p>
<ul>
<li>AppleGothic
<ul>
<li>AppleGothic</li>
</ul>
</li>
<li>Hiragino Kaku Gothic ProN
<ul>
<li>HiraKakuProN-W6</li>
<li>HiraKakuProN-W3</li>
</ul>
</li>
<li>Arial Unicode MS
<ul>
<li>ArialUnicodeMS</li>
</ul>
</li>
<li>Heiti K
<ul>
<li>STHeitiK-Medium</li>
<li>STHeitiK-Light</li>
</ul>
</li>
<li>DB LCD Temp
<ul>
<li>DBLCDTempBlack</li>
</ul>
</li>
<li>Helvetica
<ul>
<li>Helvetica-Oblique</li>
<li>Helvetica-BoldOblique</li>
<li>Helvetica</li>
<li>Helvetica-Bold</li>
</ul>
</li>
<li>Marker Felt
<ul>
<li>MarkerFelt-Thin</li>
</ul>
</li>
<li>Times New Roman
<ul>
<li>TimesNewRomanPSMT</li>
<li>TimesNewRomanPS-BoldMT</li>
<li>TimesNewRomanPS-BoldItalicMT</li>
<li>TimesNewRomanPS-ItalicMT</li>
</ul>
</li>
<li>Verdana
<ul>
<li>Verdana-Bold</li>
<li>Verdana-BoldItalic</li>
<li>Verdana</li>
<li>Verdana-Italic</li>
</ul>
</li>
<li>Georgia
<ul>
<li>Georgia-Bold</li>
<li>Georgia</li>
<li>Georgia-BoldItalic</li>
<li>Georgia-Italic</li>
</ul>
</li>
<li>Arial Rounded MT Bold
<ul>
<li>ArialRoundedMTBold</li>
</ul>
</li>
<li>Trebuchet MS
<ul>
<li>TrebuchetMS-Italic</li>
<li>TrebuchetMS</li>
<li>Trebuchet-BoldItalic</li>
<li>TrebuchetMS-Bold</li>
</ul>
</li>
<li>Heiti TC
<ul>
<li>STHeitiTC-Light</li>
<li>STHeitiTC-Medium</li>
</ul>
</li>
<li>Geeza Pro
<ul>
<li>GeezaPro-Bold</li>
<li>GeezaPro</li>
</ul>
</li>
<li>Courier
<ul>
<li>Courier</li>
<li>Courier-BoldOblique</li>
<li>Courier-Oblique</li>
<li>Courier-Bold</li>
</ul>
</li>
<li>Arial
<ul>
<li>ArialMT</li>
<li>Arial-BoldMT</li>
<li>Arial-BoldItalicMT</li>
<li>Arial-ItalicMT</li>
</ul>
</li>
<li>Heiti J
<ul>
<li>STHeitiJ-Medium</li>
<li>STHeitiJ-Light</li>
</ul>
</li>
<li>Arial Hebrew
<ul>
<li>ArialHebrew</li>
<li>ArialHebrew-Bold</li>
</ul>
</li>
<li>Courier New
<ul>
<li>CourierNewPS-BoldMT</li>
<li>CourierNewPS-ItalicMT</li>
<li>CourierNewPS-BoldItalicMT</li>
<li>CourierNewPSMT</li>
</ul>
</li>
<li>Zapfino
<ul>
<li>Zapfino</li>
</ul>
</li>
<li>American Typewriter
<ul>
<li>AmericanTypewriter</li>
<li>AmericanTypewriter-Bold</li>
</ul>
</li>
<li>Heiti SC
<ul>
<li>STHeitiSC-Medium</li>
<li>STHeitiSC-Light</li>
</ul>
</li>
<li>Helvetica Neue
<ul>
<li>HelveticaNeue</li>
<li>HelveticaNeue-Bold</li>
</ul>
</li>
<li>Thonburi
<ul>
<li>Thonburi-Bold</li>
<li>Thonburi</li>
</ul>
</li>
</ul>
<p>As you may have noted, several of the fonts are intended for non-Latin alphabets. They still include Latin glyphs, but they&#8217;re fairly bland sans-serif designs.</p>
<br />Filed under: <a href='http://excitabyte.wordpress.com/category/cocoa-libraries/'>Cocoa Libraries</a>, <a href='http://excitabyte.wordpress.com/category/user-experience/'>User Experience</a>, <a href='http://excitabyte.wordpress.com/category/user-interface/'>User Interface</a> Tagged: <a href='http://excitabyte.wordpress.com/tag/cocoa/'>Cocoa</a>, <a href='http://excitabyte.wordpress.com/tag/interface-builder/'>Interface Builder</a>, <a href='http://excitabyte.wordpress.com/tag/iphone/'>iPhone</a>, <a href='http://excitabyte.wordpress.com/tag/uifont/'>UIFont</a>, <a href='http://excitabyte.wordpress.com/tag/uilabel/'>UILabel</a>, <a href='http://excitabyte.wordpress.com/tag/user-interface/'>User Interface</a>, <a href='http://excitabyte.wordpress.com/tag/xcode/'>XCode</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=181&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2010/03/24/the-font-family-names-available-on-iphone-os/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Troubleshooting Bonjour Networking for the iPhone</title>
		<link>http://excitabyte.wordpress.com/2010/01/17/troubleshooting-bonjour-networking-for-the-iphone/</link>
		<comments>http://excitabyte.wordpress.com/2010/01/17/troubleshooting-bonjour-networking-for-the-iphone/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 00:15:07 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[GameKit]]></category>
		<category><![CDATA[GKSession]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[NSNetworkService]]></category>
		<category><![CDATA[NSNetworkServiceBrowser]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=95</guid>
		<description><![CDATA[Debugging good code running in a stable environment is hard enough.  Debugging code that responds to outside events, well, that&#8217;s even harder.  If you are an iPhone developer working with NSNetService or GKSession, then you already know this.  Despite a glut of excellent documentation on how to write code that uses these powerful classes, there is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=95&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Debugging good code running in a stable environment is hard enough.  Debugging code that responds to outside events, well, that&#8217;s even harder.  If you are an iPhone developer working with <code>NSNetService</code> or <code>GKSession</code>, then you already know this.  Despite a glut of excellent documentation on how to <em>write </em>code that uses these powerful classes, there is a dearth of documentation on how to troubleshoot and <em>debug</em> that code.  Here are my notes on lessons that I have learned along the way.  If you have a problem with your code and are stuck, hopefully they will point you in the right direction.</p>
<p>Still with me?  Then let&#8217;s dig in!</p>
<p><span id="more-95"></span></p>
<p>There are many areas where things can go wrong. Since the NSNetService instance provided to your delegate methods is autoreleased, you need to retain it if you plan on reusing it out of scope for that method. Most people will add it to an NSMutableArray or NSMutableDictionary so that it is automatically retained, and only autoreleased when removed from the collection. If that is the case for your code, make sure that you have properly initialized your collection before adding the object. Since messages to nil are perfectly ok, you may be sending the addObject:netService message to nil.  You will not receive an obvious indication that you never initialized your array or dictionary, and it will appear as though everything is working just fine&#8230;except that delegate messages &#8220;mysteriously&#8221; don&#8217;t fire off when peers change status, when you try to connect to one, etc. This crops up often enough in Bonjour troubleshooting that I would recommend it as the first place to start your troubleshooting.  It happens to the best of us. Let&#8217;s look at some code that illustrates the problem.</p>
<p>This code might look good first blush, but it will result in the &#8220;net service stops sending delegate messages&#8221; problem:</p>
<p><pre class="brush: cpp;">
//////////////// Header￼ ///////////////////////////////
# pragma mark -
# pragma mark ￼Class Header￼

#import &amp;lt;UIKit/UIKit.h&amp;gt;

@interface MyNetController : NSObject
{
		NSMutableArray *_peers;
		UITableView *_peerListTableView;
}

/////////////// ￼Property Declarations /////////////////
@property (nonatomic, assign) NSMutableArray *peers;
@property (nonatomic, assign) UITableView *peerListTableView;
@end

/////////////// Body //////////////////////////////////
# pragma mark -
# pragma mark ￼Class Implementation

@implementation MyNetController

@synthesize peers = _peers;
@synthesize peerListTableView = _peerListTableView;

- (id) init
{
	self = [super init];
	if (self != nil)
	{
		self.peers = [NSMutableArray array];
	}
	return self;
}

- (void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser
		   didFindService:(NSNetService *)netService
			   moreComing:(BOOL)moreServicesComing
{
	// Resolve the service to get our peer's name.
	[netService resolve];

	// Add the object to our collection so that
	// it gets retained for future use.
	[_peers addObject:netService];

	NSLog(@&amp;quot;Found a new peer.  Resolve started...&amp;quot;);
}

- (void)netServiceDidResolveAddress:(NSNetService *)sender
{
	// Peer will never show up in our table view.
	[_peerListTableView reloadData];

	NSLog(@&amp;quot;This line will never get printed.&amp;quot;);
}

@end
</pre></p>
<p>If you haven&#8217;t spotted it already, the problem lies in line 32.  It assigns an array to the <code>peers</code> property that will fall out of scope as soon as <code>init</code> returns.  As a result, our debug console will show &#8220;Found a new peer. Resolve started&#8230;&#8221; and that&#8217;s it.  We will never get a callback to <code>netServiceDidResolveAddress:</code>, since <code>netService</code> was autoreleased after <code>netServiceBrowser:didFindService:moreComing:</code> fell out of scope. We can fix the problem, in this case, by changing the <code>assign</code> symbol to <code>retain</code> on line 14. Now our console output will show &#8221;This line will never get printed&#8221; and our table will reload as expected.</p>
<p>Some other common issues you might want to watch out for:</p>
<ul>
<li>Make sure that your Application Protocol Name conforms to <a href="http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt" target="_blank">the RFC specifications</a>:<br />
&#8220;[There may] be no more than fourteen characters (not counting the mandatory underscore), conforming to normal DNS host name rules: Only lower-case letters, digits, and hyphens; must begin and end with lower-case letter or digit.&#8221;</li>
<li>Use <code>@""</code> instead of <code>@"local."</code> for the domain when using NSNetService.  From <a href="http://developer.apple.com/networking/bonjour/faq.html" target="_blank">Apple&#8217;s Bonjour FAQ</a>:<br />
&#8220;If you pass an empty string (&#8220;&#8221;), then Mac OS X will automatically do the right thing. In Mac OS X 10.2 and 10.3, it will register using just link-local multicast. Starting in Mac OS X 10.4, it will automatically register your service in a user-chosen unicast DNS domain as well, if applicable. You only need to pass a specific string if you have some particular reason to want to register in some specific remote domain.&#8221;</li>
<li>Bonjour does not allow for duplicate service names in the same domain. NSNetService can automatically handle this case by appending &#8221; 2&#8243; at the end of the name of the service instance.  However, this will not be the case if you are manually setting the service name.  Make sure that you write an error handler for name collisions in your <code>netService:didNotPublish:</code> method if you are passing something other than <code>nil</code> as the <code>name</code> parameter of <code>initWithDomain:type:name:port</code>.</li>
<li>The OS X mDNS responder limits how frequently you can update your TXT record.  If your TXT record update rate exceeds 10 updates per minute, it will begin to introduce progressively longer delays before sending them.  The mDNS responder will print a line similar to the following in the system.log (which you can view in XCode):</li>
</ul>
<ul>
<blockquote><p><code>Mon Aug 24 11:03:40 unknown mDNSResponder[16] &lt;Error&gt;: Excessive update rate for tester._my-app._tcp.local.; delaying announcement by 3 seconds.</code></p></blockquote>
<li>Bonjour/NSNetServiceBrowser on the iPhone/iPod Touch will utilize both Wifi and Bluetooth for service discovery&#8211;at least on supported devices.  Each time you begin browsing for services, it will search both WiFi and Bluetooth (which you can verify the log messages in the iPhone&#8217;s Console, in Organizer).  Since your Simulator &#8220;device&#8221; cannot use Bluetooth, your iPhone discovers it over WiFi.  However, if you are using NSNetService or GKSession to publish on your iPhone, then you are publishing over both WiFi *and* Bluetooth as well (if your model supports it and  Bluetooth is enabled).  NSNetServiceBrowser and GKSession, when running on BT-capable hardware, will dutifully find that both instances, and report both via delegate callbacks.</li>
<li>NSNetService and GKSession will attempt to advertise on all network interfaces that are administratively up. If you see multiple instances of the same peer, and you are using NSNetService, this may be why. To prevent that from happening, stop resolving the service once the first result comes back. In other words, in your <code>- (void)netServiceDidResolveAddress:(NSNetService *)sender</code> method, include <code>[sender stop]</code>. This should prevent your code from getting this delegate message more than once for the same peer.</li>
<li>Bluetooth PAN setup takes longer than publishing via Wifi, so the BT-discovered services will sometimes show up well after all the Wifi-based services have been discovered and resolved.  When testing two real devices, I&#8217;ve even seen both services show up in my UI (usually only after the other phone crashes).  This primarily holds true for NSNetBrowser.  I haven&#8217;t come across it yet with GKSession, though I&#8217;ve spent less time working with GameKit.  This delay does make for some frustrating coding. If you are not using GameKit, your best bet is to utilize netService:didNotResolve: to either (a) retry resolution (maybe after a timeout), or (b) invalidate the netService instance and wait for the other phone to relaunch their app.</li>
<li>If you are using multiple threads, make sure that your NSNetService gets scheduled into an actively running runloop and one that is running in default or common modes.</li>
</ul>
<p>As an aside, there is an open bug filed with Apple whereby every so often, a normal Bonjour update will not result in a delegate method getting fired.  I have only observed this occurring on a 3GS doing the monitoring.  This can result in your app slipping out of sync with the network, despite the code doing everything right.  For example, a player may show a custom TXTRecord value of &#8220;available&#8221; when they actually are &#8220;busy.&#8221;  You can diagnose this fairly readily.  Trying periodically updating the TXTRecord on a test device. If every so often one peer shows the status as &#8220;available&#8221; while the rest show show &#8220;busy,&#8221; especially if device in err is a 3GS, then you probably have encountered it (assuming each one is running the same build).</p>
<p>NSNetServiceBrowser <strong>should</strong> consistently notify its delegate whenever a service begins/ends advertising on the network (under nominal conditions).  The bug above is only an intermittent one, and apparently, hardware specific.  If you see it occurring consistently, then it&#8217;s likely that your app is the real culprit.  One easily missed problem for apps running network code on a background thread: throwing an un-handled exception on that thread.  This can occur without crashing your whole app due to Cocoa/Unix&#8217;s rules on threading. If your networking code &#8220;just stops working for no reason,&#8221; then you may want to check your iPhones Console and logs for error messages.  Make sure you have set a breakpoint on the objc_exception_throw symbol.</p>
<p>Here&#8217;s another troubleshooting technique that I&#8217;ve found invaluable: monitor Bonjour broadcasts on your dev workstation via Terminal using the dns-sd command (see below).  This will let you see all comings and goings on your local network for your service.  If your app quits, but dns-sd does not show a Remove event, then your code needs revisiting.  If dns-sd shows a remove event, but one your other apps instances doesn&#8217;t fire a delegate event then you may be seeing the above mentioned bug.  It may also be the case that your code isn&#8217;t doing what you think it&#8217;s doing.  And remember, this will only help you troubleshoot Wifi-to-Wifi service Bonjour.  Bluetooth-to-Bluetooth (PAN) networking is not supported from iPhone Simulator.</p>
<p>Here is how you use that handy command:</p>
<p><pre class="brush: bash;">
dns-sd -B _serviceName
dns-sd -L Tester _serviceName._tcp.
</pre></p>
<p>Where  serviceName is a string that identifies your Bonjour service (like &#8220;my-app&#8221;).  Don&#8217;t omit the initial underscore (e.g. &#8220;_my-app&#8221;). Replace &#8220;Tester&#8221; with the display name/service name for a particular instance (e.g. &#8220;Player 1&#8243;).  The first line shows how to display the activity of all Bonjour peers advertising your service on your network segment.  It will let you know when each peer first appears and last disappears.  It provides a timestamp each time, which can really help in correlating events among multiple peers&#8211;perfect for debugging.  If you want to watch the activity of a single peer, including monitoring the status of all TXTRecord key/value pairs, then use syntax of line 2.  This will let you know if code updates to the TXTRecord dictionary actually get written to the network (as it were).</p>
<blockquote><h6>Flaggin&#8217; It Down</h6>
<p>If you spend any time using the <code>dns-sd</code> tool, you may wonder what the &#8220;Flags&#8221; column of its output means.  There isn&#8217;t much documentation on this, so I had to dig through <a href="http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-58.5/mDNSShared/dns_sd.h">the source code</a> to find out for sure.  So that you don&#8217;t have to do the same thing, here&#8217;s what they mean (at least, when you use <code>dns-sd</code> for browsing published services):</p>
<ul>
<li><b>0</b> = REMOVE entry message (0).</li>
<li><b>1</b> = REMOVE entry message (0) plus MORE TO COME message (1).</li>
<li><b>2</b> = ADD entry message (2).</li>
<li><b>3</b> = ADD entry message (2) plus MORE TO COME message (1).</li>
</ul>
</blockquote>
<p>You may suspect, at some point, that your network may be causing problems for your application. One technique I would recommend in order to determine that for sure: <a title="How to create a computer-to-computer network" href="http://docs.info.apple.com/article.html?path=Mac/10.5/en/8339.html" target="_blank">setup an ad hoc WiFi network</a> between your Mac and your iPhone. This eliminates your wireless access point as a source of error. Just make sure that all other network connections on your Mac and iPhone are disabled first.  For example, unplug any physical Ethernet cables on your Mac, and disable Bluetooth on your iPhone.  That way GKSession will be working with just the WiFi interfaces. This setup has the added advantage of letting you build/test/debug while flying over 10,000 feet!  It also lets you write and test networking code, either Foundation networking or GKSession, using just the Simulator and your device.</p>
<p>Finally, don&#8217;t forget to test your code with real-world WiFi networks.  There are a number of factors that may be present in a network that causes trouble for your application. Public hot spots increasingly prevent individual WiFi clients from communicating with each other on same subnet (often referred to as &#8220;isolation&#8221;).  In addition, some will quarantine a network client until the user clicks through a &#8220;Terms of Service&#8221; web page. It does no good to develop an app that runs great in a lab environment, but breaks for your customers.  In fact, you may not even make it through the approval process.  If you don&#8217;t have a Q/A department with a huge testing lab at your disposal, just visit a few places with free public hot spots (e.g. Starbucks, McDonald&#8217;s, most coffee shops, hotels, big airports, etc), connect up with two or three test devices, and fire up your app on each.  This will give you an idea of how your code works in heterogenous environments.</p>
<p>I hope you find something helpful in these notes as you debug your code.  This was kind of a brain dump, so I hope some of it made some sense. And please feel free to add your own notes in the comments section.</p>
<p>Happy Coding!</p>
<br />Posted in Debugging, Networking, Uncategorized Tagged: Cocoa, Debugging, GameKit, GKSession, iPhone, Networking, NSNetworkService, NSNetworkServiceBrowser, Troubleshooting <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=95&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2010/01/17/troubleshooting-bonjour-networking-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Keeping User Defaults Synchronized with Settings.bundle</title>
		<link>http://excitabyte.wordpress.com/2009/08/12/keeping-user-defaults-synchronized-with-settings-bundle/</link>
		<comments>http://excitabyte.wordpress.com/2009/08/12/keeping-user-defaults-synchronized-with-settings-bundle/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 14:34:54 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[User Experience]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[NSUserDefaults]]></category>
		<category><![CDATA[Property Lists]]></category>
		<category><![CDATA[Settings.bundle]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=66</guid>
		<description><![CDATA[The first time you wade into the NSUserDefaults system in Cocoa, you feel sweet relief wash over you. However, you could be in for a rude awakening.  Don't worry, though.  We got 'ya covered.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=66&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The first time you wade into the NSUserDefaults system in Cocoa, you feel sweet relief wash over you.  Managing user preferences in any application can be a very tiresome chore.  NSUserDefaults is like hiring a housekeeper, only it doesn&#8217;t cost you anything.</p>
<p>Excited with the possibilities, you dive in.  You quickly have your Settings.bundle added to your project and your settings menus built.  It all looks impressive, and only took a few hours.  Woo hoo! You launch your app to watch this sorcery in action, when—bang! The app crashes.  Not cool.  A little debugging shows that the defaults you created on the root page work fine, but only if you open the your app&#8217;s Settings page before launching the program.  And child menus have the same problem, except that users have to navigate to each child menu before the defaults work.  You imagine the reaction you&#8217;ll get when you explain this to your users: I have to do whaaaat?</p>
<p><span id="more-66"></span>No worries, though.  This gap in expectations has been well discussed on <a href="http://greghaygood.com/2009/03/09/updating-nsuserdefaults-from-settingsbundle">teh</a> <a href="http://brainwashinc.wordpress.com/2009/04/14/nsuserdefaultssettingsbundle-not-loaded-returning-nils/">intertubes</a>.  In addition, Apple does provide a reference implementation in the <a title="Apple Developer Connection" href="http://developer.apple.com/iPhone/library/samplecode/AppPrefs/index.html#//apple_ref/doc/uid/DTS40007799">AppPrefs project</a>.  However, the AppPrefs project only really points you in the right direction.  The other two implementations, which extend the AppPrefs example, are a little too complex for my taste.  In addition, none of these three take advantage of one of NSUserDefaults cooler features: <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/Concepts/DefaultsDomains.html">defaults domains</a>.  When we code along in our app, we don&#8217;t want to worry about whether or not a user default has already been &#8220;initialized.&#8221;  We want to put things in our Settings.bundle plists and have them Just Work.</p>
<p>To do that, we need to do a few things.  We should really register our defaults before we do anything else.  That means it should go in our UIApplicationDelegate&#8217;s <code>applicationDidFinishLaunching:</code> method, right at the top.</p>
<p>Second, we need to submit a dictionary of all default values to the <code>standardUserDefaults</code> singleton.  It will put them in the Registration domain, which is separate from where your user&#8217;s overrides are kept.  The registration domain only exists in memory, so we must recreate it every time we run the app.  When you request a key value from NSUserDefaults, it will first look for a user-supplied value.  If it can&#8217;t find one (in memory or on disk), it will look to the values in the Registration Domain, and return that one.  That means we need to register <em>all</em> of the values included in our Settings.bundle property lists, whether we think we&#8217;ll need them or not.  Make no assumptions.  Sooner or later, we will (and if we don&#8217;t, then we should pull them out of the .plist).  This also requires us to load the .plist file on disk for each child pane (if you have any).</p>
<p>If you think about this system for a bit, though, it does make sense.  We are already storing the defaults in our .plists.  Why store a duplicate copy in the NSUserDefaults application domain database?  By not doing so, we avoid the need for synchronization, conflict resolution, etc.  We only store the user-specified values in our app&#8217;s user defaults.  That&#8217;s why our keys return nil, unless either we first register defaults, or unless the user manually sets the values (which opening the relevant Settings pane does).  Why not have NSUserDefaults automatically <code>registerDefaults</code> like we do below?  Well, I&#8217;m not sure.  You could always submit a feature request to Apple.</p>
<p>In the meantime, then, here is my solution to add to the mix:</p>
<p><pre class="brush: cpp;">
/** Loads user preferences database from Settings.bundle plists. */
+ (void)initSettingsDefaults
{
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

	//Determine the path to our Settings.bundle.
	NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
	NSString *settingsBundlePath = [bundlePath stringByAppendingPathComponent:@&quot;Settings.bundle&quot;];

	// Load paths to all .plist files from our Settings.bundle into an array.
	NSArray *allPlistFiles = [NSBundle pathsForResourcesOfType:@&quot;plist&quot; inDirectory:settingsBundlePath];

	// Put all of the keys and values into one dictionary,
	// which we then register with the defaults.
	NSMutableDictionary *preferencesDictionary = [NSMutableDictionary dictionary];

	// Copy the default values loaded from each plist
	// into the system's sharedUserDefaults database.
	NSString *plistFile;
	for (plistFile in allPlistFiles)
	{

		// Load our plist files to get our preferences.
		NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:plistFile];
		NSArray *preferencesArray = [settingsDictionary objectForKey:@&quot;PreferenceSpecifiers&quot;];

		// Iterate through the specifiers, and copy the default
		// values into the DB.
		NSDictionary *item;
		for(item in preferencesArray)
		{
			// Obtain the specifier's key value.
			NSString *keyValue = [item objectForKey:@&quot;Key&quot;];

			// Using the key, return the DefaultValue if specified in the plist.
			// Note: We won't know the object type until after loading it.
			id defaultValue = [item objectForKey:@&quot;DefaultValue&quot;];

			// Some of the items, like groups, will not have a Key, let alone
			// a default value.  We want to safely ignore these.
			if (keyValue &amp;&amp; defaultValue)
			{
				[preferencesDictionary setObject:defaultValue forKey:keyValue];
			}

		}

	}

	// Ensure the version number is up-to-date, too.
	// This is, incidentally, how you update the value in a Title element.
	NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@&quot;CFBundleVersion&quot;];
	NSString *shortVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@&quot;CFBundleShortVersionString&quot;];
	NSString *versionLabel = [NSString stringWithFormat:@&quot;%@ (%d)&quot;, shortVersion, [version intValue]];
	[standardUserDefaults setObject:versionLabel forKey:@&quot;app_version_number&quot;];

	// Now synchronize the user defaults DB in memory
	// with the persistent copy on disk.
	[standardUserDefaults registerDefaults:preferencesDictionary];
	[standardUserDefaults synchronize];
}
</pre></p>
<p>It&#8217;s important to remember the difference between the Registration Domain, and the Application Domain.</p>
<p>The general process is:</p>
<ol>
<li>Create a &#8220;myDefaults&#8221; dictionary.</li>
<li>Load a .plist file into a dictionary.</li>
<li>Copy only your default key/object pairs into &#8220;myDefaults.&#8221;</li>
<li>Repeat (2) and (3) for each .plist in your Settings.bundle.</li>
<li>&#8220;Register&#8221; your defaults using registerDefaults: by passing it your &#8220;myDefaults&#8221; dictionary.</li>
<li>Synchronize.</li>
</ol>
<p>When you perform step 5, NSUserDefaults will create a separate domain for your key/object pairs in myDefaults.  If a search of user-supplied values (a.k.a. the Application Domain) for your key turns up nil, NSUserDefaults then search for that key in the Registration Domain.</p>
<p>Let&#8217;s walk through an example.</p>
<p><strong>Assumptions:</strong></p>
<ul>
<li>Your Root.plist includes &#8220;app_player_name&#8221; and a default value of &#8220;Player 1&#8243;</li>
<li>Your Root.plist includes &#8220;app_game_difficulty&#8221; and a default value of &#8220;Easy&#8221;</li>
<li>The user has overridden &#8220;app_game_difficulty&#8221; and set it to &#8220;Hard&#8221;</li>
</ul>
<p><strong>Scenario 1:</strong><br />
<pre class="brush: cpp;">
myPlayerName = [[ NSUserDefaultsstandardUserDefaults] objectForKey:@&quot;app_player_name&quot;]
</pre><br />
In this case, <code>myPlayerName</code> will equal &#8220;Player 1.&#8221; NSUserDefaults searches the application domain for @&#8221;app_player_name&#8221;, and gets nil.  Next, it searches for <code>@"app_player_name"</code> in the registration domain and returns <code>@"Player 1"</code> since we had loaded it there using initSettingsDefaults.<br />
<pre class="brush: cpp;">
 myGameDifficulty = [[ NSUserDefaultsstandardUserDefaults] objectForKey:@&quot;app_game_difficulty&quot;]
</pre><br />
In this case, the values of both variables will be:</p>
<p><code>myGameDifficulty == @"Hard"<br />
myPlayerName == @"Player 1"</code></p>
<p>NSUserDefaults searches the application domain for <code>@"app_game_difficulty"</code>, and returns <code>@"Hard"</code>.  Now, if it had searched the registration domain, it would have found <code>@"Easy"</code>.  However, since the user-supplied value takes priority over the registered default, it still returns <code>@"Hard"</code>.</p>
<p><strong>Scenario 2:</strong></p>
<p>Now, if had <em>not</em> registered any defaults in Scenario 1, this is what we would have ended up with instead:</p>
<p><code>myGameDifficulty == @"Hard"<br />
myPlayerName == nil</code></p>
<p>Why? Because the user-supplied value of @&#8221;Hard&#8221; was stored in the Application Domain.  It didn&#8217;t matter that the Registration Domain was empty.  Since there was neither a user-supplied value in the Application Domain or a registered value in the Registration Domain, myPlayerName returned <code>nil</code>.</p>
<p>The key here is to remember that setting a default value, and registering a default value are two very different things.</p>
<p>Happy, er, Defaulting!</p>
<br />Posted in User Experience Tagged: Cocoa, NSUserDefaults, Property Lists, Settings.bundle, User Experience, User Interface <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=66&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2009/08/12/keeping-user-defaults-synchronized-with-settings-bundle/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Mysterious CALayer Object Proliferation Caused By Core Animation?!</title>
		<link>http://excitabyte.wordpress.com/2009/07/15/59/</link>
		<comments>http://excitabyte.wordpress.com/2009/07/15/59/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 00:33:42 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=59</guid>
		<description><![CDATA[Avoid wasting hours chasing down phantom memory hogs--use Instrument's Memory Monitor instead of Object Allocations. <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=59&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been reviewing some UI code that I just completed.  It&#8217;s my regular practice to check for leaks, etc., so that I can verify that my code is doing what I <em>think</em> it&#8217;s doing. I typically fire up Instruments running the Leaks monitor, and not only review any leaks that are found, but also review Object Allocation behavior.</p>
<p>I plugged a couple of leaks that sprang up, but I still could not figure out why object allocations were growing to infinity (albeit at a snail&#8217;s pace).  I could launch my app and just let it sit idle and CALayer objects were just proliferating.  I narrowed the problem down to a simple background [UIView animation] block. Surely Core Animation didn&#8217;t leak, right?</p>
<p>Turns out, the answer is: not really. <a title="CALayer and Object Allocations" href="https://devforums.apple.com/thread/19605?tstart=0"> Thanks to Apple Devforum poster Rincewind</a>, we now know:</p>
<blockquote><p>You are probably seeing a bug in ObjectAlloc. You can confirm this in one of two ways</p>
<p>1) Examine the memory address of these &#8220;leaked&#8221; objects – they will probably all be the same (or a small set of addresses).</p>
<p>2) Add the Memory Monitor instrument from the library and watch your application&#8217;s Real Memory – this is generally a far better indicator of how much memory your application is using in total anyway.</p></blockquote>
<p>Sure enough, he was right!  The objects pouring into the list on Instruments all clustered around the same few memory addresses.  Watching the physical memory confirmed that, despite the ever-growing heap in Object Allocations, physical memory was holding steady.</p>
<p>Whew! But Grrr! Hopefully you can avoid the frustration (until it&#8217;s patched).</p>
<p>Happy Debugging!</p>
<br />Posted in Debugging, Optimization, Tools Tagged: Cocoa, Debugging, Memory, Optimization, XCode <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=59&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2009/07/15/59/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Part I: Spawning Threads Using Selectors With Multiple Parameters</title>
		<link>http://excitabyte.wordpress.com/2009/07/07/spawning-threads-using-selectors-with-multiple-parameters/</link>
		<comments>http://excitabyte.wordpress.com/2009/07/07/spawning-threads-using-selectors-with-multiple-parameters/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 19:46:57 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Threading]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Introspection]]></category>
		<category><![CDATA[NSInvocation]]></category>
		<category><![CDATA[NSInvocationOperation]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=28</guid>
		<description><![CDATA[If you've spent much time working with thread in Cocoa, you have likely come across the following roadblock: you can only specify one parameter when spawn from a selector.  The answer lies in the NSInvocation class.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=28&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve spent much time working with thread in Cocoa, you have likely come across the following roadblock: you can only specify one parameter when spawning a new thread from a selector.  The first reaction is to rewrite your method with a single parameter that takes collection of objects and then unpacks them.  This can lead to untidy or prolix code, though, and doesn&#8217;t do anything for readability or debug-ability. You also need to know when you define your method that you will want to spawn it off&#8211;otherwise you face refactoring down the road.  At any rate, spawning via selector is a convenience method; we shouldn&#8217;t be forced to change our code in order to use it.</p>
<p>You can see glimmers of hope, though, as you study the problem.  Objective-C allows you to include multiple parameters in a selector, as in @selector(myMethod:withAValue:andAnother:). However, you will throw an exception at runtime since you can only specify one context object, and thus, the runtime will only have values to pass for one of the arguments. So close, and yet, so far away.  Is our only other option subclassing NSThread?  Thankfully, no.  We can have our cake and eat it, too, with just a little work on our part.  The answer lies in the NSInvocation class.<br />
<span id="more-28"></span> Huh? Invocation? The Apple developer class reference explains the idea succinctly:</p>
<blockquote><p>An <code style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;">NSInvocation</code> is an Objective-C message rendered static, that is, it is an action turned into an object &#8230; An <code style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;">NSInvocation</code> object contains all the elements of an Objective-C message: a target, a selector, arguments, and the return value. Each of these elements can be set directly, and the return value is set automatically when the <code style="font-size:11px;font-family:Monaco, Courier, Consolas, monospace;">NSInvocation</code> object is dispatched.</p></blockquote>
<p>Oooh.  Clever.  Now the class name makes more sense. Instead of <em>invoking</em> of an object&#8217;s method using source code (at design time), we take a different approach.  We use an <em>object</em> to invoke another object&#8217;s method (at runtime).  Here, Objective-C shows us just how powerful introspection can be. Now that we have NSInvocation, how do we get back to spawning off arbitrary methods with multiple parameters? We create our own convenience method.  Let&#8217;s look at an example:</p>
<p><span style="font-family:Consolas, Monaco, 'Courier New', Courier, monospace;line-height:18px;font-size:12px;white-space:pre;"> </span></p>
<p><pre class="brush: cpp;">
/** Calls arbitary methods inside of a new thread. */
- (void)performSelector:(SEL)aSelector withContext:(id)context
{
	// Before we get ahead of ourselves, let's do some
	// sanity checking on the context object pass
	// to the method.
	NSInvocationOperation *theOperation ;
	if ([context isKindOfClass:[NSArray class]])
	{
		// The docs explicity tell you not to use alloc/init,
		// but instead, use the class method invocationWithMethodSignature,
		// which takes a selector and returns its method's signature.
		NSMethodSignature *theSignature =
			[self methodSignatureForSelector:aSelector];

		// With our signature in hand, we can now call our
		// class method, which returns a usable (and autoreleased)
		// NSInvocation instance.
		NSInvocation *theInvocation =
			[NSInvocation invocationWithMethodSignature:theSignature];

		// Now for the real automagic fun!  We will loop through our context array,
		// and match up each parameter with the corresponding value
		// passed to us in our array.  First we will check to see if the there
		// are the same number of parameters and argument values (always nice).
		// Since we know context is a kind of NSArray, we cast it as one.
		NSArray *parameterValues = (NSArray *)context;
		NSUInteger parameterCount = [parameterValues count];

		// Objective-C actually converts selectors into C methods, and
		// some of that behind-the-scenes chicanary will affect us here.
		// To get an idea of how, let's look at the official guidance:

	      /* From SDK Docs:

		 NSInvocation Class Reference ...
		 There are always at least 2 arguments, because an NSMethodSignature
		 object includes the hidden arguments self and _cmd, which are the
		 first two arguments passed to every method implementation.

		 NSMethodSignature Class Reference ...
		 Indices 0 and 1 indicate the hidden arguments self and _cmd,
		 respectively; you should set these values directly with the
		 setTarget: and setSelector: methods. Use indices 2 and greater
		 for the arguments normally passed in a message.
		 */

		NSUInteger argumentCount = [theSignature numberOfArguments] - 2;

		if (parameterCount == argumentCount)
		{
			[theInvocation setTarget:self];		 // There's our index 0.
			[theInvocation setSelector:theSelector]; // There's our index 1.

			// Now for arguments 2 and up...
			NSUInteger i, count = parameterCount;

			for (i = 0; i &lt; count; i++) {

				// We're agnostic about object types, so assume nothing.
				id currentValue = [parameterValues objectAtIndex:i];

				// Well, not entirely agnostic. We do have one problem
				// case that is likely to occur somewhat frequently.
				//
				// Objective-C data types, like int, float, etc., are
				// not objects.  We can't pass them in an array. However,
				// there are many methods that take these types of
				// parameters.  Since we have a goal of supporting
				// arbitrary methods--without modifying them--we need
				// some way to transport these.  A quick and simple way
				// so to wrap them in an NSValue object, then add them
				// to our array.
				//
				// Good so now we have our NSValue.  Now what? Well,
				// now we need to unwrap the basic value nestled inside.
				// Once tranformed, we can pass it as a parameter.
				// Here's how we do that:
				//
				// Test to see if we have a foundation class
				// wrapped in an NSValue.
				if ([currentValue isKindOfClass:[NSValue class]])
				{
					void *bufferForValue;
					[currentValue getValue:&amp;bufferForValue];
					[theInvocation
						setArgument:&amp;bufferForValue
						atIndex:(i + 2)];
					// The +2 represents the (self) and (cmd) offsets
				} else
				{
					[theInvocation
						setArgument:&amp;currentValue
						atIndex:(i + 2)];
					// Again, our +2 represents (self) and (cmd) offsets
				}
			}
			// That's it! (For our NSInvocation).
		}
		// Now we use the invocation to create our operation, which I explain
		// a bit more about below.  I'm including it as reference, since
		// there are good advantages to using a queue.
		theOperation = [[NSInvocationOperation alloc]
					initWithInvocation:theInvocation];
	}
	else
	{	// Okay. We were not passed an array in our context parameter.
		// Well, that's just fine.  If we received something, we'll just
		// pass it on.  This way, our users don't have to go through the
		// hassle of creating an NSArray of just one item.  We could check
		// to see if our selector has just one parameter, and then ensure
		// that context is not nil, but that's left as an exercise to
		// the reader.
		// Note, context is of type (void), so it doesn't need to be
		// wrapped/unwrapped in an NSValue object.  Woo hoo!
		// Invoke a selector with a single parameter.
		theOperation = [[NSInvocationOperation alloc]
					initWithTarget:self
					selector:NSSelectorFromString(aSelector)
					object:context];
	}
	// In this example, I'm submitting my NSInvocationOperation
	// to an NSOperationQueue, which I have already built using
	// a singleton pattern.  You could also use NSThread, but
	// there are some pluses to using NSInvocationQueues for my
	// application (and probably yours too). For NSThread, you
	// use NSInvocation instead of NSInvocationOperation, and
	// might end up with something like:

	// [theInvocation performSelectorInBackground:@selector(invoke) withObject:nil]

	// where the invoke selector is sent to theInvocation, telling it to
	// call the method with the arguements as we defined above, but on
	// a background thread.  The other performSelector* methods work similarly.
	//
	// In this case, though, I'm adding my operation to the queue.
	// Add the operation to the internal operation queue
	// managed by our application delegate.
	[[myAppDelegate sharedOperationQueue] addOperation:theOperation] ;

	// Make sure theOperation gets released later, once it's it finished running.
	[theOperation release];
}
</pre></p>
<p>To invoke our, er, invocation, we just send a message like:<br />
<pre class="brush: cpp;">[self performSelector:@selector(myMethodWithA:andB:andC:)
        withContext:myArrayOfObjects];</pre></p>
<p>Pretty convenient, and very flexible.  When using the built-in convenience methods that Apple provides, the object that you pass to the <code>withObject:</code> parameter is retained automatically.  This is not the case, by default, when using NSInvocation.  If your code relies on that auto-retain, not to worry.  All you need to do is add <code>[theInvocation retainArguments]</code> before you invoke (say at line 21 above).</p>
<p>Let&#8217;s take a breath.  We covered a lot of ground&#8230;but not all of it.  When you&#8217;re ready, test your endurance with <a href="http://excitabyte.wordpress.com/2010/05/18/part-ii-spawning-threads-using-selectors-with-multiple-parameters/">Part II of this article</a>, where we streamline our new code.</p>
<br />Posted in Threading Tagged: Cocoa, Introspection, NSInvocation, NSInvocationOperation, Threading <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=28&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2009/07/07/spawning-threads-using-selectors-with-multiple-parameters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
		<item>
		<title>Extracting localization strings from Settings.bundle plists</title>
		<link>http://excitabyte.wordpress.com/2009/07/01/extracting-localization-strings-from-settings-bundle-plists/</link>
		<comments>http://excitabyte.wordpress.com/2009/07/01/extracting-localization-strings-from-settings-bundle-plists/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 19:12:23 +0000</pubDate>
		<dc:creator>Zack</dc:creator>
				<category><![CDATA[Localization]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://excitabyte.wordpress.com/?p=3</guid>
		<description><![CDATA[If you are building child panes in your Settings.bundle, you'll end up with several .plist files. When it comes time to localize your project, you find the creation of the corresponding .strings file a bit tedious.  Here's a handy list bash script which will speed things up.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=3&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="font-size:14px;vertical-align:baseline;background-image:initial;background-repeat:initial;background-attachment:initial;background-color:transparent;clear:both;background-position:initial initial;border:0 initial initial;margin:0 0 1em;padding:0;">
<p style="font-size:14px;vertical-align:baseline;background-image:initial;background-repeat:initial;background-attachment:initial;background-color:transparent;clear:both;background-position:initial initial;border:0 initial initial;margin:0 0 1em;padding:0;">If you are building child panes in your Settings.bundle, you&#8217;ll end up with several .plist files. When it comes time to localize your project, you find the creation of the corresponding .strings file a bit tedious (I know I do).</p>
<p style="font-size:14px;vertical-align:baseline;background-image:initial;background-repeat:initial;background-attachment:initial;background-color:transparent;clear:both;background-position:initial initial;border:0 initial initial;margin:0 0 1em;padding:0;">Here&#8217;s a handy list bash script which will (i) find tags, (ii) extract the contents of the following tag, and then (iii) output that value to a text file in the &#8220;string&#8221; = &#8220;string&#8221; format needed for ibtool.</p>
<p style="font-size:14px;vertical-align:baseline;background-image:initial;background-repeat:initial;background-attachment:initial;background-color:transparent;clear:both;background-position:initial initial;border:0 initial initial;margin:0 0 1em;padding:0;"><span id="more-3"></span>You pass the input and output file names as parameters.</p>
<p><pre class="brush: cpp;">
#!/bin/sh
echo &quot;//Manual edits will be overwritten the next time this script runs.// Generated by plist2strings.\n/* A single strings file, whose title is specified in your preferences schema. The strings files provide the localized content to display to the user for each of your preferences. */\n&quot; &gt; plist2stringstmp
sed -n '
# look for a &quot;#&quot; at the end of the line
/&lt;key&gt;Title&lt;\/key&gt;$/ {
# Found one - now read in the next line
	N
# delete the &quot;#&quot; and the new line character,
	s/.*&lt;\(string\)&gt;\(.*\)&lt;\/\1&gt;/&quot;\2&quot; = &quot;\2&quot;/gp
}' $1 &gt; plist2stringstmp2
cat plist2stringstmp plist2stringstmp2 &gt; $2
rm plist2stringstmp plist2stringstmp2
</pre></p>
<p>Copy-N-Paste into a text file. I saved mine as plist2strings. Be sure to give it execute permissions. For example, in Terminal execute:</p>
<p><pre class="brush: bash;"> macbook:~ foo$ chmod 755 plist2strings</pre></p>
<p>To execute the script (if saved to your user folder) from root of your Settings.bundle directory, just use the syntax:</p>
<p><pre class="brush: bash;"> macbook:~ foo$ ~/plist2strings mysettings.plist en.lprog/mysettings.strings</pre></p>
<p>If mysettings.strings is not already present in that folder, it will create it. If it is already there, it will automatically overwrite it without warning.</p>
<p>Hope someone finds this useful. And feel free to use (and abuse) as you see fit (caveat emptor <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ). If you make any useful changes, consider posting them back up here for others to enjoy too.</p>
<p>Happy Localizing!</p>
<br />Posted in Localization Tagged: Bash, i18n, Interface Builder, Localization, XCode <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/excitabyte.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/excitabyte.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/excitabyte.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/excitabyte.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/excitabyte.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/excitabyte.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/excitabyte.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/excitabyte.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/excitabyte.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/excitabyte.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/excitabyte.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/excitabyte.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/excitabyte.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/excitabyte.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=excitabyte.wordpress.com&amp;blog=8402054&amp;post=3&amp;subd=excitabyte&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://excitabyte.wordpress.com/2009/07/01/extracting-localization-strings-from-settings-bundle-plists/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81fafc55d911d1e99824fb5a42d147ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zack</media:title>
		</media:content>
	</item>
	</channel>
</rss>
