<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Perspx &#187; Cocoa</title>
	<atom:link href="http://perspx.com/blog/archives/tag/cocoa/feed/" rel="self" type="application/rss+xml" />
	<link>http://perspx.com</link>
	<description>Musings of a teenage programmer</description>
	<lastBuildDate>Thu, 20 May 2010 06:56:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making Cocoa list views really fast</title>
		<link>http://perspx.com/blog/archives/1427/making-list-views-really-fast/</link>
		<comments>http://perspx.com/blog/archives/1427/making-list-views-really-fast/#comments</comments>
		<pubDate>Thu, 20 May 2010 06:55:20 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Echofon]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Tweetie]]></category>

		<guid isPermaLink="false">http://perspx.com/?p=1427</guid>
		<description><![CDATA[It seems that many of the apps in use today rely on or display feeds or lists of data; be that a Twitter timeline, an RSS feed or a list of history in a version control system, there&#8217;s a common trend in UI for using lists.
But displaying lists in applications can be much more than trivial, certainly for applications on  ... ]]></description>
			<content:encoded><![CDATA[<p>It seems that many of the apps in use today rely on or display feeds or lists of data; be that a Twitter timeline, an RSS feed or a list of history in a version control system, there&#8217;s a common trend in UI for using lists.</p>
<p>But displaying lists in applications can be much more than trivial, certainly for applications on Mac OS X, especially when you have to deal with large quantities of data, and have to solve problems such as variable row heights or changes to this information.</p>
<p>Ever since using <a href="http://www.atebits.com/tweetie-mac/">Tweetie</a>, a Twitter client for Mac OS X, from a development point of view I was always curious as to how the list view for the Twitter timeline was implemented; hundreds of rows of tweets can be displayed in this control, and the performance hit appears to be minimal; scrolling is smooth, there doesn&#8217;t appear to be a huge memory footprint. So how is it done?</p>
<h2>Lists in Tweetie</h2>
<p>If you <a href="http://www.codethecode.com/projects/class-dump/">class-dump</a> Tweetie, you can see three classes at work:</p>
<ul>
<li><strong>ABScrollView</strong>: A subclass of <code>NSScrollView</code>. It&#8217;s not clear as to why there is this subclass but an <code>ABColor</code> object is used for the background (as opposed to an <code>NSColor</code>).</li>
<li><strong>ABTableView</strong>: A subclass of <code>ABScrollView</code> which is used as the list control.</li>
<li><strong>ABTableViewCell</strong>: The cell class used to display each row in <code>ABTableView</code>.</li>
</ul>
<p>The interesting part of the class hierarchy is contained in <code>ABTableView</code> and <code>ABTableViewCell</code>. <code>ABTableView</code> is a subclass of <code>ABScrollView</code> (<em>not</em> <code>NSTableView</code>) and is a control which can display a list of <code>ABTableViewCell</code>s. However the real misnomer here is the <em>cell</em> part, because <code>ABTableViewCell</code> is a subclass of <code>NSView</code>, and not <code>NSCell</code>.</p>
<p><a href="http://perspx.com/wp-content/uploads/2010/04/TweetieClassDiagram.png"><img class="aligncenter size-full wp-image-1434" title="Tweetie lists class diagram" src="http://perspx.com/wp-content/uploads/2010/04/TweetieClassDiagram.png" alt="" width="356" height="313" /></a></p>
<p>So essentially what we have here is an implementation of something similar to <code>NSCollectionView</code>, which has a set of subviews which each represent a row and have their own place in the view hierarchy. But how, then, is the Tweetie list view so performant?</p>
<pre class="prettyprint">@interface ABTableView : ABScrollView
{
    ...
    NSMutableDictionary *reusableTableCells;
    ...
}

...
- (id)reusableCellsArrayForIdentifier:(id)arg1;
- (id)dequeueReusableCellWithIdentifier:(id)arg1;
...
@end</pre>
<h3>Reusing Cells</h3>
<p>The answer seems to lie in a method declared on <code>ABTableView</code>, which is <code>-dequeueReusableCellWithIdentifier:</code>. For those of you who are iPhone developers, you will be familiar with a method on <code>UITableView</code> with <em>exactly</em> the same method signature.</p>
<p>For those who aren&#8217;t, I shall explain: certainly compared to simple <code>NSCell</code> instances, <code>NSView</code> instances are pretty expensive. In fact, <code>NSCell</code> is <em>actually designed</em> as a &#8220;mechanism for displaying text or images in an NSView without the overhead of a full NSView subclass&#8221;<sup>1</sup>. In light of this, if we have 100, 1,000 – or even more – rows in a list, we don&#8217;t want the overhead of 1,000 instances of <code>NSView</code>, each used to represent a row. What&#8217;s more is that most of these cached views are wasted, since 1,000 rows cannot be displayed in the viewport at the same time. The iPhone takes advantage of this, and ensures that there are only enough view (in this case <code>UIView</code>) instances to cover the height of the table view; if the associated rows are scrolled off screen, then the views are removed from the view hierarchy.</p>
<p>Scrolling works much like laying down track for a train by picking up track from behind it; when a row is scrolled so that it is no longer visible, it is removed from the table view and &#8220;enqueued&#8221; (ie stored in an array); when a row that is not visible is scrolled so that it becomes visible, the data source should first check to see if there are any enqueued views, and if so it is then added to the view hierarchy and displayed.</p>
<p>What this means is that hundreds of rows can be displayed in one control without a large performance hit, and is one of the optimizations that makes the iPhone UI so responsive.</p>
<h2>Lists in Echofon</h2>
<p>After class-dumping, you can see that Echofon implements their list views in pretty much the same way as Tweetie, using two main classes:</p>
<ul>
<li><strong>FastTableView</strong>: A subclass of <code>NSScrollView</code> which is the list control.</li>
<li><strong>FastTableCell</strong>: A subclass of <code>NSView</code> which represents a cell used for the table view.</li>
</ul>
<p><a href="http://perspx.com/wp-content/uploads/2010/04/EchofonClassDiagram.png"><img class="aligncenter size-full wp-image-1438" title="Echofon Class Diagram" src="http://perspx.com/wp-content/uploads/2010/04/EchofonClassDiagram.png" alt="" width="356" height="253" /></a></p>
<p>Although not as explicit as the enquing/dequeuing in Tweetie&#8217;s list control, it would <em>seem</em> that <code>FastTableView</code> does a similar job as it has declared on it <code>-popCellForRow:fromArray:</code> and <code>-popSpareCell</code>.</p>
<p>Also to note is the use of <code>NSControl</code> and <em>not</em> <code>NSView</code> as the superclass of the table &#8220;cell&#8221; object, unlike with Tweetie. I would guess that this is for some of the additions that <code>NSControl</code> provides, perhaps the target/action mechanism.</p>
<h2>Final word</h2>
<p>When displaying large amounts of data in a list, as many applications do, often <code>NSTableView</code> is not enough. It is a pretty performant class, but when you start doing things with variable row heights, it isn&#8217;t really cut for the job. Nor is a class such as <code>NSCollectionView</code>; again it doesn&#8217;t implement variable row heights and lots of items can slow it down.</p>
<p>It seems that using view objects for each row, which have an established presence in the view hierarchy is the way to go, if you have the optimizations on top of this. For one you get the added convenience of using instances of <code>NSView</code>, and not simply working with <code>NSCell</code>.</p>
<p>As a final note, a quote I recall from <a href="http://www.zarrastudios.com/ZDS/Home/Home.html">Marcus Zarra</a>&#8217;s <a href="http://www.amazon.com/Core-Data-Apples-API-Persisting/dp/1934356328">book on Core Data</a> says:</p>
<blockquote><p>The lesson I took away from that story is to expect my users to put thousands of times as much data into my application as I would ever consider reasonable</p></blockquote>
<p>When working with large quantities of data, it is these kinds of optimizations that make your app more responsive and provide a better experience to the user.</p>
<div id="footnotes">
<h2>Footnotes</h2>
<ol>
<li>From <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ControlCell/Concepts/AboutControlsCells.html">Control and Cell Programming Topics for Cocoa: About Cells and Controls</a></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/1427/making-list-views-really-fast/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>NSConference 2010: Mac Developer Conference (Day 2)</title>
		<link>http://perspx.com/blog/archives/1253/nsconf-2010-mac-developer-conference-day-2/</link>
		<comments>http://perspx.com/blog/archives/1253/nsconf-2010-mac-developer-conference-day-2/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 17:29:32 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[nsconf]]></category>
		<category><![CDATA[nsconference]]></category>

		<guid isPermaLink="false">http://perspx.com/?p=1253</guid>
		<description><![CDATA[
It was the second and final day of the NSConference 2010 Mac Developer Conference and most delegates were tired and a little hungover. But there was another great line up of speakers for the day, and it was another day of socialising and fun, as well as all that other learning stuff.
Perhaps the biggest things I took away from the  ... ]]></description>
			<content:encoded><![CDATA[<div id="attachment_1275" class="wp-caption aligncenter" style="width: 610px"><img class="size-full wp-image-1275 " title="Core Audio" src="http://perspx.com/wp-content/uploads/2010/02/Core_audio.jpg" alt="" width="600" height="382" /><p class="wp-caption-text">Rentzsch on Core Audio: The API of Rock Stars</p></div>
<p style="text-align: center;">
<p>It was the second and final day of the <code>NSConference</code> 2010 Mac Developer Conference and most delegates were tired and a little hungover. But there was another great line up of speakers for the day, and it was another day of socialising and fun, as well as all that other learning stuff.</p>
<p>Perhaps the biggest things I took away from the Mac conference was taking a pragmatic approach to anything which became a recurring theme in a lot of the talks – like yesterday&#8217;s conference, extremes were presented such as Dave on not using singletons, but at the end of the day it&#8217;s a judgement call and you shouldn&#8217;t do or not do something &#8216;because Dave said it&#8217;, but rather because it&#8217;s either right or not right for what you want to do. There was also some recurring memes, such as The Matrix and kitties, which snuck their way into certain presenters&#8217; talks, but most of all, I learnt that people <em>can</em> be (fairly) civil when discussing version control, and also that the GPL <em>sucks</em>.<strong> </strong></p>
<h2>Jeff LaMarche – Writing Super Superclasses</h2>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/lamarche_objc_runtime.jpg"><img class="alignleft size-full wp-image-1264" title="Jeff LaMarche" src="http://perspx.com/wp-content/uploads/2010/02/jeff_lamarche.jpg" alt="" width="288" height="230" /></a>Jeff was still jetlagged and tired, and made <em>several</em> comments as such throughout his talk. However, despite this, his talk on the Objective-C runtime was very interesting and informative to listen to. He started the talk off with a cliché – &#8216;you can&#8217;t see the forest through the trees&#8217; – and likened this to software development. As developers we are often too pedantic and only focus on the little things, but we also need to be able to step back and look at our projects as a whole on a larger scale.</p>
<p>He then went into the guts of his talk, talking about such things as dynamic method resolution and introspection at a lower level. He introduced Objective-C as different from other languages in terms of the patterns used and also touched on a criticism by others that it is missing things, however this is <em>by design</em> and not simply an oversight.</p>
<p>He then started talking about his <a href="http://code.google.com/p/sqlitepersistentobjects/">SQLitePersistentObjects</a> project which leverages the Objective-C runtime in several ways, and then demonstrated some of these features such as dynamic method resolution using IMPs and was well explained with the associated pros and cons of using certain runtime features.  Like many of the other talks, he explained the limitations of using the runtime, for example Apple <em>may</em><em> not</em> approve apps for the App store that use it, and also to be pragmatic about its use and not simply use it because you can.</p>
<h2>Andy Finnell – Brushing up on OpenCL</h2>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/finnell_opencl.jpg"><img class="alignright size-full wp-image-1266" title="Andy Finnell" src="http://perspx.com/wp-content/uploads/2010/02/andy_finnell.jpg" alt="" width="288" height="194" /></a>I&#8217;ll be honest, after listening to Andy&#8217;s talk, I felt stupid. And I think there were other attendees around the room who were in a similar boat. He opened up with a demo, which was a great start to his talk, a demo which simulated the effect of watercolours on a canvas, and leveraged OpenCL to provide the graphics and calculate the drawing of the pigment and the interaction with the surface.</p>
<p>Although the maths and physics was way above me (and wasn&#8217;t helped by lack of sleep) it was still an informative and interesting talk, and I liked the structure of the presentation – cool demo at the beginning which made you interested then the rest of the time spent explaining how it all worked.</p>
<p>Andy also opened with a short intro on OpenCL and how it operated which was nice for those who hadn&#8217;t been at Drew&#8217;s Concurrency workshop on Sunday, however it would have been nice for this section to be expanded a bit, with less of a focus on the mechanics of the demo.</p>
<p>The presentation was also entertaining with accommodation for British spellings (&#8220;watercolo(u)r&#8221;) which is always a nice touch and other comical remarks and slides which helped a bit when it came to digesting the hardcore code samples. The coding side was also a nice contrast from the higher-level talks that were presented over both days of the Mac conference which also made it a useful and informative talk.</p>
<h2>Dave Dribin – Version Control System Shoot Out</h2>
<p>[Apologies for not having an accompanying photo]</p>
<p>Dave&#8217;s talk was all about version control and mostly a history or comparison of the different VCS&#8217;s out there. There was a feeling before the talk that <a href="http://twitter.com/creednmd/status/8539677234">it could go</a> <a href="http://twitter.com/pilky/status/8539592251">horribly wrong</a> but Dave kept it pretty objective and didn&#8217;t particularly favour any of the VCS&#8217;s.</p>
<p>He presented the history of version control systems first, with SCCS, RCS, CVS, SVN and other systems that use similar acronyms, before moving onto distributed version control with Git, Mercurial and Bazaar, quoting Linus&#8217;s talk where he explained the naming for Git: &#8216;I&#8217;m an egotistical bastard and I name all my products after myself, first Linux and now Git&#8217;. With all the version control systems he presented the pros and cons, and only discredited Git slightly. Overall a pretty well rounded talk for the allotted time of about 35 mins.</p>
<h2>Graham Lee – Code Signing</h2>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/code_signing.jpg"><img class="alignleft size-full wp-image-1271" title="Graham Lee" src="http://perspx.com/wp-content/uploads/2010/02/graham_lee.jpg" alt="" width="320" height="206" /></a>Graham had been given the opportunity to present at very short notice, and it was very well executed. It was astounding the quality and detail of his talk despite the little preparation time that he had, and he had a great presentation style which was very entertaining. He also included lots of puns and other fun comments, such as a reference to a hypothetical harmful piece of injected code which he called Malicious Monster and also referenced as Malicious Library. For those who didn&#8217;t attend, the reference to the Matrix had become kind of a meme by this point and even though Graham had prepared his presentation in about 24 hours he still managed to fit it in.</p>
<p>He also did a live demo which was very useful and demonstrated some of the code signing in action; he also anticipated our needs well by cutting a few minutes short in aid of food. Overall a brilliant, informative presentation.</p>
<h2>Aaron Hillegass – The Many Faces of Data Persistence</h2>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/hillegass_data_persistence.jpg"><img class="alignright size-full wp-image-1272" title="Aaron Hillegass" src="http://perspx.com/wp-content/uploads/2010/02/aaron_hillegass.jpg" alt="" width="320" height="269" /></a>Aaron&#8217;s talk was – as you probably guessed – focused on data persistence and the what the options are on Mac OS X. He started off by stating &#8216;The file is dead&#8217; and explaining how his HDD is essentially a cache for data that is stored in the Cloud, which prompted him to comment &#8216;Long live the cache!&#8217;. He used the example of iWork on the iPad in that it uses a &#8220;Library&#8221; to store files which is essentially an abstraction for the filesystem and that this is the way forward.</p>
<p>He then went on to talk about archiving in Cocoa and Cocoa Touch, discussing Keyed vs Unkeyed archiving and the associated pros and cons. He also presented a timeline of events in terms of data persistence, from the early 90&#8217;s with NeXT right up until Core Data in 2005. He presented some nicely formatted object graphs of some of the Core Data things which was also useful.</p>
<p>He spent most of the second half of the presentation talking about his new data persistence project, <a href="http://github.com/hillegass/BNRPersistence">BNRPersistence</a>, which provides classes that wrap Tokyo Cabinet which is used to store the data, which received much applause from everyone when he announced that it was open-source, available on GitHub, and <em>not</em> licensed under the GPL. It was certainly an interesting project and he had some numbers for certain cases compared to Core Data and it performed much faster. But he was dealing with object graphs that had 1K and 1M objects and for &#8220;everyday&#8221; use with smaller objects it was unclear whether BNRPersistence would be better than Core Data because he didn&#8217;t have any figures on it.</p>
<p>What I liked about Aaron&#8217;s talk which I don&#8217;t think any of the other speakers did was that he was more engaging with everyone whilst he was talking – his style was like a lecture, but he periodically checked that we were all following everything, something which I guess comes from the teaching which he does, and was a nice touch.</p>
<h2>Cocoa Rumble</h2>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/cocoa_rumble.jpg"><img class="alignleft size-full wp-image-1285" title="Cocoa Rumble" src="http://perspx.com/wp-content/uploads/2010/02/cocoa_rumble_small2.jpg" alt="" width="320" height="192" /></a>The rest of the allotted time had been reserved for something different, in the form of a &#8220;Cocoa Rumble&#8221;. Earlier in the day, Scotty had announced that people could put their names in a hat to be chosen for this mystery event. Names were picked out of this hat and each person chosen was assigned a speaker from the conference.</p>
<p>The combined speakers and delegates were then split up into three groups and had to pick from the hat which now contained another set of slips of paper, which had written on them different &#8220;Core–&#8221; frameworks. The three chosen were Core Text, Core Audio and Core Image, and the teams had some time to prepare a presentation for why their framework was the &#8220;Core of the Year&#8221;. All presentations were very entertaining, with talks from Mike, Wolf and Graham and at the end, Core Image (presented by Graham) won for the compelling reasons that he had put into a table.</p>
<p>Whilst the teams were preparing, there was also a chance for the speakers and some of the delegates to provide tips, and there were some great tips from such people as <a href="http://twitter.com/uliwitness">Uli</a> who provided a load of cool Xcode tips, Aaron on <a href="http://twitter.com/Perspx/status/8549070326">having the old Xcode documentation browsing behaviour</a>, and Jeff on conditional build settings.</p>
<p>A nice fun end to the day, with something different and all in the community and social spirit.</p>
<h2>Final thoughts</h2>
<p>It was my last day of <code>NSConference</code> and what a brilliant conference it had been, with Matt Gemmell&#8217;s workshop on Sunday and the Mac developer conference too. It was great to socialise with loads of Mac developers who were all really friendly and I entered into some interesting discussions, and I took a great deal away from the conference which was something that Scotty laid out as one of the goals at the beginning.</p>
<p>I would like to thank Scotty, Tim, Dave, Rob, Simon and all the other people who made <code>NSConference</code> possible, because it was a great experience indeed, and to all the great people that I met there. Thanks also to Uli for setting up the <a href="http://twitter.com/nsconfr">NSConference Reflector</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/1253/nsconf-2010-mac-developer-conference-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSConference 2010: Mac Developer Conference (Day 1)</title>
		<link>http://perspx.com/blog/archives/1210/nsconference-2010-mac-developer-conference-day-1/</link>
		<comments>http://perspx.com/blog/archives/1210/nsconference-2010-mac-developer-conference-day-1/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 08:21:54 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[nsconf]]></category>
		<category><![CDATA[nsconference]]></category>

		<guid isPermaLink="false">http://perspx.com/?p=1210</guid>
		<description><![CDATA[
It was the first day of the NSConference 2010 Mac developer conference and a great lineup was ahead.
In terms of the day generally, it was a brilliant experience. It was well organised and many thanks go to Scotty, Tim, Dave and all the other NSConference staff. The WiFi (although irritating that you had to keep filling out the signup form)  ... ]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/02/nsconf.jpg"><img class="aligncenter size-full wp-image-1249" title="NSConference" src="http://perspx.com/wp-content/uploads/2010/02/nsconf.jpg" alt="" width="640" height="330" /></a></p>
<p>It was the first day of the <code>NSConference</code> 2010 Mac developer conference and a great lineup was ahead.</p>
<p>In terms of the day generally, it was a brilliant experience. It was well organised and many thanks go to Scotty, Tim, Dave and all the other <code>NSConference</code> staff. The WiFi (although irritating that you had to keep filling out the signup form) worked quite well and you could get some pretty good speeds, which was good considering that the room was filled with over 100 developers, almost all of which I imagine had a Mac or iPhone for most of the day.</p>
<p>It was also a great social event, and the breaks were a nice chance to go around and talk to someone you&#8217;d never met before and have some interesting discussions. It was also nice to be in this tight community, separated from all the &#8220;normal&#8221; people who were also around at the venue.</p>
<p>In terms of the talks generally, I felt that they were all very well done and it was clear that they had put a lot of work into them. The presentations were very well laid out and simple, and not wordy and the speakers all obviously knew what they were talking about and had lots of interesting things to say. However one big thing that I felt could be improved on was the interaction with the audience – that is, many of the slides were in more of a lecture-style and although a couple made up for this with a Q&amp;A at the end I thought this could be improved upon.</p>
<h2>The Speakers</h2>
<h3>Scotty</h3>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/IMG_1426.jpg"><img class="alignleft size-full wp-image-1224" title="Scotty" src="http://perspx.com/wp-content/uploads/2010/02/scotty_thumb.jpg" alt="" width="294" height="211" /></a>Scotty kicked off the morning with a nice introduction to the conference, welcoming everyone and thanking us all for being here. He presented his recent case of being rushed into hospital for a &#8220;routine&#8221; operation as a metaphor for what we&#8217;re doing here, and he explained how even though he has little knowledge of the detailed ins and outs of the medical profession, he had a respect for them due to the reputation that the collective members have earned over the years. This was related to Mac development and <em>our</em> collective &#8216;responsibility to the platform&#8217; and what we do, and the expectations of the Mac or iPhone platforms which is ultimately our responsibility. He also talked about how there is pioneering but also sharing of ideas in the medical profession and again linked this to our role in the Mac/iPhone/iPad community.</p>
<p>He also went on to talk about the community spirit, and emphasised that all the speakers had given up their own time (and money) to be here which because of this, and was a nice to start the day.</p>
<h3>Mike Lee – Conference Keynote: Engineering Life</h3>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/IMG_1430.jpg"><img class="alignright size-full wp-image-1226" title="Mike Lee" src="http://perspx.com/wp-content/uploads/2010/02/mike_lee_thumb.jpg" alt="" width="294" height="218" /></a>Mike&#8217;s presentation was evidently something slightly different and original to start the day but was a nice sideline to our ability to crank code, and was more thinking at a higher level about what we do, and perhaps being a bit more philosophical about it. He was relating what we do and our profession to life in general, and how we can &#8216;engineer life&#8217;. He defined <em>problems</em> as &#8216;reality we do not like&#8217; which was a topical tie-in with software development since problem solving is one of the key aspects to what we do.</p>
<p>Mike also used several anecodes during his presentation which brought in a realistic sense rather than something purely theoretical, reality which is often missed when talking about software and software development, with purely theoretical statements. He also likened the Universe to a computer in that both are simply entities which are constantly changing state.</p>
<p>The next part of the talk became perhaps a little morbid with discussion on &#8216;Death 101&#8242; with the conclusion that &#8216;death sucks&#8217; but you can&#8217;t really do anything about it and you&#8217;ll be dead in the ground so won&#8217;t care about it anyway. However he also likened this to fear and how you can engineer your way around fear and tackle it head-on rather than let it get the better of you. He also talked about having a legacy and a part of you that lives on when you die by accomplishing something that you are remembered for, which can perhaps give you a kind of immortality.</p>
<p>He finished on the note of &#8216;be the hero&#8217;, and overall the talk was an interesting and somewhat unusual. I heard later on that there was about a 50/50 split on people who liked/disliked the presentation but I thought it was an interesting, though-provoking topic and good to be a part of.</p>
<h3>Wolf Rentzsch – Spelunking OS X</h3>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/IMG_1434.jpg"><img class="alignleft size-full wp-image-1227" title="Wolf Rentzsch" src="http://perspx.com/wp-content/uploads/2010/02/wolf_rentzsch_thumb.jpg" alt="" width="294" height="221" /></a>Wolf started with the statement that he had &#8216;90 slides in 60 minutes&#8217; and it was pretty fast-paced, although for the most part fine to follow. He dug into Mac OS X under the hood and ways you can access this information and interact with it, introducing such tools as otx, otool and class-dump.</p>
<p>The low-level nature of his talk was a great contrast to Mike&#8217;s previous talk which was a demonstration of the breadth of talks within <code>NSConference</code> and was more of a code and tool-based talk. He introduced hexadecimal editors such as HexFiend, which &#8216;are your friend&#8217;, then went on to deal with different sections with prying into OS X internals such as static analysis with strings and files, and code injection.</p>
<p>The great part of presenting these tools was the accompanying screenshots of a terminal and the associated output, and also examples of useful commands and how they could be used, which was probably the killer feature of the presentation for me. He also had a clear presentation style and after talking to him later at the bar was a nice, bubbly person to talk to and obviously knows his stuff.</p>
<p>As a suggestion for improvement it would have been nice to see a live demo of some of the tools in action – he had some screenshots of probing applications such as TextEdit, but a live demo of the tools live would have been a nice addition.</p>
<h3>Dave Dribin – Clean Code</h3>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/IMG_1437.jpg"><img class="alignright size-full wp-image-1229" title="Dave Dribin" src="http://perspx.com/wp-content/uploads/2010/02/dave_dribin_thumb.jpg" alt="" width="294" height="230" /></a>I think that Dave&#8217;s presentation was perhaps my favourite of the day and talked about different ways of writing clean code and bad ways that can introduce &#8220;code smell&#8221; and ways to get around this and I agree that it is an important part of being a programmer.</p>
<p>He used the analogy of the iPhone as a way into the presentation; with the divide between internal and external quality – the external beauty is the interface that is seen by the user but the internals are the code that we write and sits behind the scenes. With an application it&#8217;s the difference between a beautiful interface and the underlying implementation of that in code.</p>
<p>The presentation was filled with quite a lot of tips, such as guidelines on naming classes and common principles such as DRY (Don&#8217;t Repeat Yourself) and OAOO (Once and Only Once) with the example of using enumerations or constants for dictionary keys instead of repeating strings throughout your code.</p>
<p>The Q&amp;A was also useful and for most of the other talks there wasn&#8217;t time so it was a nice feature to be able to ask questions about the content discussed.</p>
<h3>Drew McCormack – Data Presentation in Mac Apps</h3>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/IMG_1438.jpg"><img class="alignleft size-full wp-image-1230" title="Drew McCormack" src="http://perspx.com/wp-content/uploads/2010/02/drew_mccormack_thumb.jpg" alt="" width="294" height="214" /></a>Drew lead into the presentation by talking about his scientific background and explaining how different data can be displayed and visualised in different ways. His presentation was also nice because it was one of the ones that wasn&#8217;t directly related to churning code and was more about the UI and talking about the various controls – standard or custom – and where they are best used.</p>
<p>I liked the format of looking at these different controls – he presented images of each and then talked about the advantages and disadvantages of each. This was particularly useful when comparing controls, such as the <code>NSTableView</code> and the <code>NSCollectionView</code>, and his slides were perhaps the best of the day and contained very little text on them, just visual cues such as images and the likes.</p>
<p>To this end I learnt a lot about how different views are implemented – he explained using Tweetie (Mac) as an example that it uses an <code>NSTableView</code> to display its list of data, and also Versions implements some of its custom controls using HTML, CSS and Javascript with WebKit.</p>
<p>Near the end he did talk about non-standard controls and focused on drawing graphs with CorePlot. However he spent quite a long time talking about this, which although interesting it would have been nicer if he&#8217;d demonstrated a few more, different controls.</p>
<h3>Marcus Zarra – Core Animation</h3>
<p><a href="http://perspx.com/wp-content/uploads/2010/02/IMG_1440.jpg"><img class="alignright size-full wp-image-1231" title="Marcus Zarra" src="http://perspx.com/wp-content/uploads/2010/02/marcus_zarra_thumb.jpg" alt="" width="294" height="209" /></a>Marcus started his talk by explaining how Core Animation wasn&#8217;t just for designers, and used himself as an example of a non-designer, but that it could still be used to enhance or help create sleek interfaces. However he also warned that Core Animation can easily be overused and turn a simple, clean UI into something horrible and even very unintuitive. He also explained how Core Animation, although its interface is quite simple, it is also very powerful.</p>
<p>He gave a few examples of using Core Animation, and then gave a live demo of an application that was doing lots of complex animations using Core Animation and how smooth and seamless they all were. It was evident that he had spent a lot of time on the project and he explained how the rotating gears displayed were constructed as paths which was a nice touch to the talk, to get a real demo application.</p>
<p>However even though he had an hour slot, he only used about 35 minutes talking and left the rest of the time for questions, which was quite a nice idea since it was more engaging with everyone rather than simply a lecture. However, it would have been nice for him to use more of his allotted time to show some more Core Animation examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/1210/nsconference-2010-mac-developer-conference-day-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NSConference 2010: The World According to Gemmell</title>
		<link>http://perspx.com/blog/archives/1193/the-world-according-to-gemmell/</link>
		<comments>http://perspx.com/blog/archives/1193/the-world-according-to-gemmell/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 19:47:29 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[matt gemmell]]></category>
		<category><![CDATA[nsconf]]></category>
		<category><![CDATA[nsconference]]></category>
		<category><![CDATA[workshop]]></category>

		<guid isPermaLink="false">http://perspx.com/?p=1193</guid>
		<description><![CDATA[
The first day of NSConference 2010 kicked off with two workshops – Concurrency Programming on Snow Leopard by Drew McCormack, and The World According to Gemmell, by the Legend himself, of which I was an attendee.
The session started with a discussion about a certain recently released Apple product which was very interesting and allowed us to present our thoughts on  ... ]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-1194" title="Matt Legend Gemmell at NSConference 2010" src="http://perspx.com/wp-content/uploads/2010/01/IMG_1420.jpg" alt="" width="600" height="428" /></p>
<p>The first day of <a href="http://nsconference.com/"><code>NSConference</code> 2010</a> kicked off with two workshops – <em>Concurrency Programming on Snow Leopard</em> by Drew McCormack, and <em>The World According to Gemmell</em>, by <a href="http://mattgemmell.com/">the Legend himself</a>, of which I was an attendee.</p>
<p><a href="http://perspx.com/wp-content/uploads/2010/01/andy_ipad.jpg"><img class="alignright size-full wp-image-1295" title="Andy's iPad mockup" src="http://perspx.com/wp-content/uploads/2010/01/andy_ipad_small.jpg" alt="" width="235" height="314" /></a>The session started with a discussion about a <a href="http://www.apple.com/ipad/">certain recently released Apple product</a> which was very interesting and allowed us to present our thoughts on the device. We covered such areas as the human psychology behind it, the display of &#8220;real&#8221; objects as the interface and the much more emphasised touch interaction including two-handed UI, as well as getting &#8220;wanky&#8221; about the emotional connection with the device.</p>
<p><a href="http://twitter.com/creednmd">Andy</a> had also created a great model of the device, that was the exact dimensions (although the back didn&#8217;t slope like the real thing) and half the weight of an actual iPad. This was really useful in the talk from Matt, when he was explaining such things as how people would hold the device.</p>
<p>We also discussed the changing seeds of user interfaces and the switch away from clutter-based interfaces, such as inspector panels which &#8216;can edit anything that has ever lived&#8217;.</p>
<h2 style="clear: both;"><em>Our</em> workshop</h2>
<p>A few weeks ago Matt sent an email round to all the workshop attendees asking whether we had any UX topics that we wanted to discuss that could form the basis of the workshop. This was a great structure and in the session we got through 7 or 8 discrete topics, from such topics as the evolution of your app and removing features to when the best time to release your 1.0 is.</p>
<p>Although Gemmell said that he had put the slides together quickly and a bit haphazardly (and <a href="http://twitter.com/macdevnet">Scotty</a> had been fiddling around with the slide animations<span class="required">*</span>), the slides were well arranged, and contained only a few – although thought-provoking – bullet points for each topic, and allowed us to really discuss the ins and outs and how one would go about dealing with these problems. The workshop dynamic really helped this section and the group discussion bit was great as we could all have our opinions heard and commented on, with Matt being the suspiciously-bearded ringleader of the event.</p>
<h2>Workshop dynamic</h2>
<p>Matt&#8217;s talk was arranged as a workshop and consisted of around 30 people. The tables had also been arranged into groups of about 5 or 6 and all of this combined made a great, much more personal dynamic for the session, because as Matt himself put it, we were all participants and it was <em>our</em> workshop, not just his.</p>
<p>It was a great social occasion to this end, and allowed for group collaboration which was a real strength of the workshop and made it a really enjoyable event.<em></em></p>
<h2>Final thoughts</h2>
<p>A brilliant first day to <code>NSConference</code> and a great thought experiment with lots of things to take away and think about. As I mentioned when speaking to Matt in one of the breaks, the Mac/iPhone/iPad platforms are so brilliant partially due to the fusion and interwoven nature of code <em>and </em>design, the latter of which is given a lot of thought in most instances, which made the workshop a very topical and interesting one indeed.</p>
<p>The Mac conference (Monday 1st Jan &#8211; Tuesday 2nd Jan) has a lot to live up to but a great start to what I&#8217;m sure will be a great conference.</p>
<div style="font-size: 10px; color: #606060;">* I&#8217;m kidding, we all know that it was <a href="http://twitter.com/tarasis">Rob</a> – he was being suspiciously quiet.</div>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/1193/the-world-according-to-gemmell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Parsing command line arguments with NSUserDefaults</title>
		<link>http://perspx.com/blog/archives/1122/parsing-command-line-arguments-nsuserdefaults/</link>
		<comments>http://perspx.com/blog/archives/1122/parsing-command-line-arguments-nsuserdefaults/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 19:18:29 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[command line arguments]]></category>
		<category><![CDATA[NSArgumentDomain]]></category>
		<category><![CDATA[NSUserDefaults]]></category>

		<guid isPermaLink="false">http://perspx.com/?p=1122</guid>
		<description><![CDATA[The NSUserDefaults class provides Cocoa applications access to the underlying Mac OS X defaults system, and can be used to store and persist user preferences.
Whilst providing an interface to the defaults system, the NSUserDefaults class can also be used to access command line arguments that were passed when the executable was launched, which have already been parsed and are accessed  ... ]]></description>
			<content:encoded><![CDATA[<p>The <code>NSUserDefaults</code> class provides Cocoa applications access to the <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/defaults.1.html">underlying Mac OS X defaults system</a>, and can be used to store and persist user preferences.</p>
<p>Whilst providing an interface to the defaults system, the <code>NSUserDefaults</code> class can also be used to access command line arguments that were passed when the executable was launched, which have already been parsed and are accessed in the same way that other defaults are. This can be a great convenience when dealing with applications that accept command line arguments, such as command line tools.</p>
<h2>Defaults domains</h2>
<p>Defaults are organised into <em>domains</em>, each of which are assigned a name and are used to separate defaults intended for different purposes. Domains can either be <em>persistent</em> or <em>volatile</em> – persistent domains persist their defaults to disk and remain if the application is terminated and relaunched. Volatile domains only exist from the point at which they are created to when the user defaults object is deallocated.</p>
<p>The standard defaults domains – listed in order of precedence – are:</p>
<ol>
<li><code>NSArgumentDomain</code> – this is a volatile domain that contains any command line arguments that were passed when the application was executed.</li>
<li>The application-specific domain – the persistent domain that is based on the application&#8217;s bundle identifier. At current the defaults for this domain are stored in a .plist file at <code>~Library/Preferences/&lt;ApplicationIdentifier&gt;.plist</code></li>
<li><code>NSGlobalDomain</code> – a global defaults domain that is intended for use by all applications running under the user that the domain applies to.</li>
<li>Languages Domain – these are volatile domains used for language-specific defaults based on languages set in the <code>NSGlobalDomain</code> under the <code>AppleLanguages</code> key.</li>
<li><code>NSRegistrationDomain</code> – a volatile domain that allows &#8220;factory settings&#8221; to be set by the application. This provides a fallback so that the application can always rely on <code>NSUserDefaults</code> to return a value for certain defaults, even if they have not yet been overridden and saved in the defaults database in the application-specific or global domain (this is useful on first launch, for example).</li>
</ol>
<p>The order of precedence is important – when you request a value for a given key, the defaults domains are searched in this order. The first key that is found that matches the requested key is used. This means that, for example, if a key is present in the application-specific domain and also in the global domain, the value set in the application-specific domain will always be found first and used.</p>
<h2>Parsing command line arguments with the NSArgumentDomain</h2>
<p>The <code>NSArgumentDomain</code> is a particularly useful domain for applications that use command line arguments.  The domain is volatile, and when created the defaults dictionary is populated with any command line arguments that were passed when the application was executed.</p>
<p>Command line arguments that can be parsed and used by the <code>NSArgumentDomain</code> must take the format:</p>
<pre>-name value</pre>
<p>The argument is stored as a default with key of <em>name</em> and value of <em>value</em>.</p>
<p>At this point accessing values passed in on the command line is the same process for accessing any other defaults. For example running an application as such:</p>
<pre>MyApplication -aString "Hello, World" -anInteger 10</pre>
<p>Allows the command line arguments to be retrieved as such:</p>
<pre class="prettyprint">NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];

NSString *aString = [standardDefaults stringForKey:@"aString"];
NSInteger anInteger = [standardDefaults integerForKey:@"anInteger"];

NSLog (@"aString argument: %@\nanInteger argument: %d", aString, anInteger);</pre>
<p>With the following output:</p>
<pre>aString argument: Hello, World
anInteger argument: 10</pre>
<h2>The importance of domain precedence</h2>
<p>The <code>NSArgumentDomain</code> has the highest precedence when a key is searched for in the user defaults, and as such defaults set in different domains with the same keys as the command line arguments will be temporarily overridden. For example, if the application is invoked from the command line as follows:</p>
<pre>MyApplication -myKey "Foo"</pre>
<p>but <code>myKey</code> also exists in the application-specific defaults domain with a value of &#8220;Bar&#8221;, then calling:</p>
<pre class="prettyprint">[[NSUserDefaults standardUserDefaults] valueForKey:@"myKey"];</pre>
<p>will return &#8220;Foo&#8221;. The default set in the application-specific domain is <em>not</em> overwritten, but the default in the <code>NSArgumentDomain</code> is encountered first as it has the highest precedence.</p>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/1122/parsing-command-line-arguments-nsuserdefaults/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PXSourceList: Source List Control for Mac OS X</title>
		<link>http://perspx.com/blog/archives/1096/pxsourcelist/</link>
		<comments>http://perspx.com/blog/archives/1096/pxsourcelist/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 17:02:31 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[source list]]></category>

		<guid isPermaLink="false">http://perspx.com/?p=1096</guid>
		<description><![CDATA[Source Lists feature in many Mac OS X applications. From iTunes to iCal to Versions, they are a great navigation control.
But for us Cocoa developers, they aren&#8217;t that easy to implement. You can easily create an NSOutlineView and set its highlight mode to &#8220;Source List&#8221; but none of the other Source List features come built in out of the box,  ... ]]></description>
			<content:encoded><![CDATA[<p><a href="http://developer.apple.com/Mac/library/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGWindows/XHIGWindows.html#//apple_ref/doc/uid/20000961-CHDDIGDE" target="_blank">Source Lists</a> feature in many Mac OS X applications. From iTunes to iCal to Versions, they are a great navigation control.</p>
<p>But for us Cocoa developers, they aren&#8217;t that easy to implement. You can easily create an <code>NSOutlineView</code> and set its highlight mode to &#8220;Source List&#8221; but none of the other Source List features come built in out of the box, such as the ability to display badges or icons for items.</p>
<div id="attachment_1103" class="wp-caption aligncenter" style="width: 595px"><a href="http://perspx.com/wp-content/uploads/2010/01/pxsourcelist1.jpg"><img class="size-full wp-image-1103" title="PXSourceList" src="http://perspx.com/wp-content/uploads/2010/01/pxsourcelist1.jpg" alt="" width="585" height="322" /></a><p class="wp-caption-text">PXSourceList</p></div>
<p>I created <code>PXSourceList</code> to help address this issue. It is a reusable control (within the context of Source Lists) compatible with Mac OS X 10.5 and higher. It makes implementing Source Lists in your applications easier by adding the following main features:</p>
<ul>
<li>Automatic <em>Group</em> highlighting of top-level items – the text for Group items appears in a dark blue colour and is normally displayed as capitalized.</li>
<li>Support for <em>Badges</em> – these are dark blue capsules displayed to the right of certain items that display a number.</li>
<li>The option to display an <em>Icon</em> for each row – a small image that provides extra visual information for each row.</li>
<li>Right-clicking support to display context menus.</li>
</ul>
<h2>Getting the control</h2>
<p>The source is available to download <a href="http://github.com/Perspx/PXSourceList">from GitHub</a>.</p>
<h2>More Information</h2>
<p>More information about <code>PXSourceList</code> is available from the <a href="http://perspx.com/software/PXSourceList/">project page</a>.</p>
<p>There is also documentation available – a link to this can be found on the <a href="http://perspx.com/software/PXSourceList/">main project page</a> or from the <a href="http://github.com/Perspx/PXSourceList/">page on GitHib</a>.</p>
<p>If you have any other questions then feel free to <strong><a href="http://perspx.com/contact/">get in touch</a></strong> and I&#8217;ll be happy to help.</p>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/1096/pxsourcelist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful Interface Builder Features</title>
		<link>http://perspx.com/blog/archives/1003/useful-interface-builder-features/</link>
		<comments>http://perspx.com/blog/archives/1003/useful-interface-builder-features/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 20:26:05 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[cocoa-touch]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[interface builder]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://perspx.com/?p=1003</guid>
		<description><![CDATA[Interface Builder is one of Apple&#8217;s developer tools, used to design interfaces for both Mac OS X and iPhone applications, and in most instances saves developers huge amounts of time from having to write the equivalent code, whilst also providing a useful visual representation of the interfaces they are working on.
Some developers try and fight Interface Builder, and would rather  ... ]]></description>
			<content:encoded><![CDATA[<p>Interface Builder is one of Apple&#8217;s developer tools, used to design interfaces for both Mac OS X and iPhone applications, and in most instances saves developers huge amounts of time from having to write the equivalent code, whilst also providing a useful visual representation of the interfaces they are working on.</p>
<p>Some developers <a href="http://stackoverflow.com/questions/717442/how-do-i-create-cocoa-interfaces-without-interface-builder" target="_blank">try and fight</a> Interface Builder, and would rather code up the interfaces rather than let Interface Builder do most of the work for them. Of course, there are instances where this may be useful, but in the grand scheme of things IB is a tool which has lots of useful features that makes interface design a much easier process.</p>
<h2>Layout and alignment</h2>
<p>Interface Builder provides blue guides to aid positioning of objects, in accordance with the <a href="http://perspx.com/blog/archives/454/apple-human-interface-guidelines/" target="_blank">Apple Human Interface Guidelines</a>. However, if you want a tighter grain of control over the layout, there are other guides which help you with this.</p>
<p>Pressing <strong>option</strong> with an interface object selected causes red arrows to be displayed on the four sides of the object, with labels displaying the number of pixels from the frame of the object to the edges of the container.</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/option-spacing-guides.jpg"><img class="aligncenter size-full wp-image-1017" title="IB Layout: Spacing guides" src="http://perspx.com/wp-content/uploads/2010/01/option-spacing-guides.jpg" alt="" width="337" height="262" /></a></p>
<p>With the option key still held down, placing the cursor over another interface object will show you the spacing between the frame of the selected object and the frame of the object you have the cursor over. This can be useful in times when making sure objects have equal alignments with neighbouring objects, or within the window itself.</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/option-spacing-guides2.jpg"><img class="aligncenter size-full wp-image-1018" title="IB Layout: Spacing guides" src="http://perspx.com/wp-content/uploads/2010/01/option-spacing-guides2.jpg" alt="" width="332" height="255" /></a></p>
<p>There are also the <em>Align Vertical Center in Container</em> and <em>Align Horizontal Center in Container</em> options from the <em>Layout &gt; Alignment</em> menu which are useful in centering objects within their container (and which I personally think should also have keyboard shortcuts associated with them).</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/alignment.jpg"><img class="aligncenter size-full wp-image-1019" title="IB Layout: Alignment menu" src="http://perspx.com/wp-content/uploads/2010/01/alignment.jpg" alt="" width="410" height="309" /></a></p>
<h2>Option-drag to duplicate objects</h2>
<p>It really does what it says on the tin. To duplicate objects just hold down the option key then drag an object. A clone of the object will be created which you can then move to the desired location.</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/option-drag.jpg"><img class="aligncenter size-full wp-image-1021" title="IB: Option-drag to duplicate objects" src="http://perspx.com/wp-content/uploads/2010/01/option-drag.jpg" alt="" width="377" height="247" /></a></p>
<h2>Decompose and Simulate Interface</h2>
<p>These are two useful options that are accessible from the <em>File</em> menu.</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/decompose_simulate_interface.jpg"><img class="aligncenter size-full wp-image-1022" title="IB File Menu" src="http://perspx.com/wp-content/uploads/2010/01/decompose_simulate_interface.jpg" alt="" width="341" height="309" /></a></p>
<p>The first is <em>Decompose Interface</em>. An advantage of using NIBs is that they can be loaded lazily – that is, only when the contained objects are actually needed by the application. This can reduce the memory footprint and loading times, which is particularly useful when developing iPhone applications due to the somewhat limited system resources available.</p>
<p>Therefore a common design pattern for Cocoa/Cocoa-Touch applications is to share different objects – be that menus, windows, view controllers and such – across multiple nibs – not necessarily one per nib, but perhaps two or three that are needed for a particular part of the application and have to be loaded together. What the <em>Decompose Interface</em> action does is split objects in the current nib into separate nibs, which can then be saved and then loaded lazily by the application in this way.</p>
<p>The other action, <em>Simulate Interface</em>, is a convenience when designing an interface; instead of having to go back to Xcode and Build and Run to see what the interface looks like, you can do it straight from Interface Builder, which will simulate the current window and its contents.</p>
<p>However, note that if you use any custom views, any custom visual or behavioural attributes will not be implemented by the simulator – it does not build your application, just simulates the available objects used by your interfaces from the Library.</p>
<h2>Size to Fit</h2>
<p><em>Size to Fit</em> is an option available from the <em>Layout</em> menu (or ⌘=) which resizes a view to a size just large enough to fit its contents.</p>
<p><a href="http://perspx.com/wp-content/uploads/2010/01/sizetofit.jpg"><img class="aligncenter size-medium wp-image-1023" title="IB: Size To Fit menu option" src="http://perspx.com/wp-content/uploads/2010/01/sizetofit-300x155.jpg" alt="" width="300" height="155" /></a></p>
<p>This is useful after changing the contents of an element to then resize it to just the right size to fit its contents.</p>
<h2>Precise selection of Views in the view hierarchy</h2>
<p>This is another really useful feature of Interface Builder; when making a selection, hold down <strong>shift</strong> and then <strong>right-click</strong> on an element. A menu will pop up, which lists the views in the view hierarchy for that element, from the enclosing Window (or other appropriate top-level container) to the interface object that you have clicked on. For example, when clicking on an <code>NSButton</code>, the menu lists <em>Window, Content View, Push Button</em> and<em> Button Cell</em>.</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/rightclickselection.png"><img class="aligncenter size-full wp-image-1024" title="rightclickselection_thumb" src="http://perspx.com/wp-content/uploads/2010/01/rightclickselection_thumb.png" alt="" width="290" height="315" /></a></p>
<p>Where I&#8217;ve found this to be particularly useful is with Table Views; the particular part of the table that you want to select very much depends on what you want to do; if you are binding to a column for instance, you will want to select the table column; if you are resizing the headers, you will want to select the header view; if you want to change the row height, you want to select the Table View itself, and so forth.</p>
<p>Selection of these individual components is rather difficult and annoying, and you often have to time your clicks appropriately to select the part of the Table View that you want. However, shift-right-clicking on the Table View means that you can select the appropriate item – be that the table column, the cell for a column or the Table View itself – by selecting the appropriate item from the popup menu.</p>
<h2>Smart Groups</h2>
<p>Smart Groups can be created in Interface Builder much like smart groups in applications such as the Finder or iTunes. These are listed in the Library window, along with the other object groupings.</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/smart-groups.png"><img class="aligncenter size-full wp-image-1027" title="smart groups_thumb" src="http://perspx.com/wp-content/uploads/2010/01/smart-groups_thumb.png" alt="" width="464" height="264" /></a></p>
<p>Smart Groups provide a means of filtering objects based on a predicate (or filter) based on such properties as object label, the most recently used objects, or the kind of class an object is. This last property can be especially useful. For example, if you want a Smart Group that lists all <code>NSView</code> objects or subclasses, you can set the predicate to:</p>
<pre>&lt;Is A Kind Of&gt; NSView</pre>
<p>And the group will contain all <code>NSView</code> classes or subclasses.</p>
<p>Smart Groups can be created by clicking on the actions button at the bottom of the Library window and selecting <em>New Smart Group</em>.</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/new_smart_group.jpg"><img class="aligncenter size-full wp-image-1038" title="IB: New Smart Group" src="http://perspx.com/wp-content/uploads/2010/01/new_smart_group.jpg" alt="" width="290" height="259" /></a></p>
<h2>Font Menu</h2>
<p>Another useful menu is the <em>Font</em> menu, which allows you to set the font and font attributes of items in your interface. This can be useful when setting fonts of controls or cells, such as changing the font size, weight or colour of a cell in an <code>NSTableView</code>, for example, which saves you having to do it with code.</p>
<p><a href="http://perspx.com/wp-content/uploads/2010/01/fontsmenu.jpg"><img class="aligncenter size-full wp-image-1030" title="IB Font Menu" src="http://perspx.com/wp-content/uploads/2010/01/fontsmenu.jpg" alt="" width="241" height="342" /></a></p>
<h2>Info Panel</h2>
<p>The Info panel provides useful information about the nib that you are currently editing and its contained objects. It allows you to specify a deployment and development target, and shows any errors that your interface may have when deploying to that target.</p>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2010/01/Info-panel.jpg"><img class="aligncenter size-full wp-image-1029" title="IB Info Panel" src="http://perspx.com/wp-content/uploads/2010/01/Info-panel.jpg" alt="" width="462" height="265" /></a></p>
<p>For example, placing an <code>NSCollectionView</code> instance in a window and selecting a deployment target of Mac OS X 10.4 will show an error that the <code>NSCollectionView</code> class is not supported on versions of OS X prior to 10.5.</p>
<p>The Info panel can also show useful information about layout, for example if a window lies partially hidden off the screen which means that it will be partially hidden from view when unarchived and displayed.</p>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/1003/useful-interface-builder-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcoding made easier</title>
		<link>http://perspx.com/blog/archives/206/xcoding-made-easier/</link>
		<comments>http://perspx.com/blog/archives/206/xcoding-made-easier/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 11:56:31 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://oneinfinitemonkey.wordpress.com/?p=206</guid>
		<description><![CDATA[After the popularity of my post on the useful features of Xcode, titled Xcoding Made Easy, I decided to write a followup post detailing more features about the IDE which help make developing applications a much easier process.
Project Breakpoints

Breakpoints are a great convenience method for debugging your code. However, if you have lots of breakpoints, how do you manage them  ... ]]></description>
			<content:encoded><![CDATA[<p>After the popularity of <a href="http://perspx.com/blog/archives/44/xcoding-made-easy/">my post on the useful features of Xcode</a>, titled <em>Xcoding Made Easy</em>, I decided to write a followup post detailing more features about the IDE which help make developing applications a much easier process.</p>
<h2>Project Breakpoints</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/08/breakpoints_groupsandfiles.jpg"><img class="alignleft size-full wp-image-811" title="Project breakpoints" src="http://perspx.com/wp-content/uploads/2009/08/breakpoints_groupsandfiles.jpg" alt="" width="204" height="204" /></a><br />
Breakpoints are a great convenience method for debugging your code. However, if you have lots of breakpoints, how do you manage them all easily?</p>
<p>When you add a breakpoint it appears in the <em>Breakpoints</em> folder in the <em>Groups &amp; Files</em> list under <em>Project Breakpoints</em>. From here, you can turn breakpoints on and off and remove them, and change the conditions or add/remove breakpoint actions easily (from the accompanying detail view shown above the Editor pane) without having to navigate to each breakpoint directly. This is a great convenience for batch methods, such as removing all breakpoints.</p>
<p>Groups of breakpoints can also be created, by right-clicking on any number of breakpoints and selecting <em>Group</em> from the context menu.</p>
<p><a href="http://perspx.com/wp-content/uploads/2009/08/breakpoints_list1.jpg"><img class="alignright size-full wp-image-812" title="Breakpoints list" src="http://perspx.com/wp-content/uploads/2009/08/breakpoints_list1.jpg" alt="" width="290" height="139" /></a></p>
<p>Breakpoints for a specific source file can also be easily shown using the breakpoints popup list button in the Editor window, which lists the breakpoints detailing the method they are set in, and the line number that they apply to. Clicking on a breakpoint in the list will navigate to the source file and highlight the row that that breakpoint is applied to.</p>
<h2>Class Navigation</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/08/class_navigation_location1.jpg"><img class="size-full wp-image-813 alignleft" title="Class Navigation" src="http://perspx.com/wp-content/uploads/2009/08/class_navigation_location1.jpg" alt="" width="204" height="138" /></a><br />
Class navigation is a convenience for exploring the class hierarchy for a given class. It presents itself as a popup menu in the Editor window, which lists the superclasses, the class itself and any categories present on the class. The class that the menu displays information about is flexible: if the text caret in the editor window is within a class interface (between <code>@interface</code> and <code>@end</code>) or a class implementation (between <code>@implementation</code> and <code>@end</code>), the class navigation popup menu will provide information about that class.</p>
<p><a href="http://perspx.com/wp-content/uploads/2009/08/class_navigation_popup.jpg"><img class="alignright size-full wp-image-814" title="Class navigation popup" src="http://perspx.com/wp-content/uploads/2009/08/class_navigation_popup.jpg" alt="" width="220" height="178" /></a></p>
<p>This is a useful tool, especially when subclassing an existing class. Since subclassing builds on the existing functionality and implementation of a class (or classes), it may often be necessary to access inherited instance variables or provide custom implementations for inherited methods. By simply clicking on the class name of a superclass in the class navigation menu, you are taken to the superclass interface, which details the instance variables and methods which you can extend in your subclass.</p>
<h2>Code Folding and Focus Follows Selection</h2>
<p>As any Objective-C programmer knows, it is not the most<em> </em>concise language in the world – it is far from it, and it is so with some reason. However, this can make the readability of your source files difficult, especially if you are working with a class that has lots of methods implemented.</p>
<p><a href="http://perspx.com/wp-content/uploads/2009/08/code_folding1.jpg"><img class="alignleft size-medium wp-image-815" title="Code folding" src="http://perspx.com/wp-content/uploads/2009/08/code_folding1-300x124.jpg" alt="" width="300" height="124" /></a></p>
<p><em>Code Folding</em> and <em>Focus Follows Selection</em> are two options from the <em>View</em> menu which help to increase the readability of code. Code Folding is a way of folding functions and other braced parts of code into stubs, which makes the code dramatically more easy to read, whilst still providing the first line of a function or code block to show what the folded code is a part of. It can be applied from the <em>View &gt; Code Folding</em> menu, with menu items to fold the code block that the text caret is currently placed in, unfold all items in the current source file, fold/unfold all methods and functions, and fold/unfold all comment blocks.</p>
<p><a href="http://perspx.com/wp-content/uploads/2009/08/focus_follows_selection1.jpg"><img class="alignright size-medium wp-image-816" title="Focus follows selection" src="http://perspx.com/wp-content/uploads/2009/08/focus_follows_selection1-300x161.jpg" alt="" width="300" height="161" /></a></p>
<p><em>Focus Follows Selection</em> is another feature used to help readability. When this is turned on, Xcode will highlight the block of code that the text caret is placed in (be it a method/function or other parenthesised block such as an <code>if</code> statement) and dim the rest of the editing area, making it easier to see in which block you are working. This can be very useful for nested loops or where there is nesting of braced pieces of code. It is presented as a checkable menu item in the <em>View &gt; Code Folding</em> menu</p>
<h2>Smart Groups</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/08/smart_groups1.jpg"><img class="alignleft size-medium wp-image-817" title="Smart groups" src="http://perspx.com/wp-content/uploads/2009/08/smart_groups1-266x300.jpg" alt="" width="266" height="300" /></a></p>
<p>Smart Groups are a way of organising your project files based on a filter. Selecting <em>Project &gt; New Smart Group</em> from the menu and then either <em>Simple Filter Smart Group</em> or <em>Simple Regular Expression Smart Group</em> allows you to create a Smart Group based on a wildcard expression (for example, <code>*.nib</code> would match all files ending in <code>.nib</code>) or a regular expression. You can also select where Xcode starts looking for files in the project folder hierarchy by changing the value in the &#8220;Start From:&#8221; dropdown box. You can then also select whether the group applies to all projects created in Xcode, or just the project that you are currently working on.</p>
<p>This is an easy way to keep your project(s) organised for you, which can reduce clutter across the <em>Groups &amp; Files</em> list. As with all folders in the hierarchy in the <em>Groups &amp; Files</em> list, it is purely virtual – that is, any items placed in Smart Groups will have no effect on their physical location on disk.</p>
<p>There are two Smart Groups that are present with Xcode by default &#8211; &#8220;Implementation Files&#8221; and &#8220;NIB Files&#8221;, which contain the project&#8217;s implementation and NIB files respectively.</p>
<h2>Splitting the Editor View</h2>
<p style="text-align: center;"><a href="http://perspx.com/wp-content/uploads/2009/08/editor_splitviews1.jpg"><img class="aligncenter size-large wp-image-818" title="Multiple editor views" src="http://perspx.com/wp-content/uploads/2009/08/editor_splitviews1-1024x650.jpg" alt="" width="393" height="250" /></a></p>
<p><a href="http://perspx.com/wp-content/uploads/2009/08/editor_splitview1.jpg"><img class="alignleft size-full wp-image-819" title="Add another editor view" src="http://perspx.com/wp-content/uploads/2009/08/editor_splitview1.jpg" alt="" width="241" height="146" /></a>Often it is useful to edit more than one source file at the same time, in the same editor window. This can be achieved easily by clicking on the Split Editor View button. This will add an extra editor view to the current window, resizing the other editor view(s) to fit. Then, when files are selected from the source list they will be loaded into the currently active editor view. There is an editor bar for each editor view (containing the history list, and method list etc) which is applicable to that view. There is also a resizing separator between the editing views to allow you to resize them.</p>
<p style="clear: both;"><a href="http://perspx.com/wp-content/uploads/2009/08/editor_closeview1.jpg"><img class="alignright size-full wp-image-820" title="Close editor view" src="http://perspx.com/wp-content/uploads/2009/08/editor_closeview1.jpg" alt="" width="196" height="152" /></a><br />
Editor views can then also be easily removed by clicking on the Close Editor view button on that pane, located under the split editor view button for that editor view. This will resize the other editor views accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/206/xcoding-made-easier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa Memory Management Etiquette</title>
		<link>http://perspx.com/blog/archives/182/cocoa-memory-management-etiquette/</link>
		<comments>http://perspx.com/blog/archives/182/cocoa-memory-management-etiquette/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 19:13:47 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://oneinfinitemonkey.wordpress.com/?p=182</guid>
		<description><![CDATA[I often find myself answering questions on Stack Overflow where users question whether they are managing memory correctly. I often refer to Apple&#8217;s guide on Object Ownership and Disposal, from the Memory Management Programming Guide for Cocoa, since this explains why what they are doing is either correct or incorrect.
Notably are the object &#8220;ownership&#8221; conventions which the guide outlines. Ownership  ... ]]></description>
			<content:encoded><![CDATA[<p>I often find myself answering questions on <a href="http://stackoverflow.com">Stack Overflow</a> where users question whether they are managing memory correctly. I often refer to Apple&#8217;s guide on <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043-SW1">Object Ownership and Disposal</a>, from the Memory Management Programming Guide for Cocoa, since this explains <em>why</em> what they are doing is either correct or incorrect.</p>
<p>Notably are the object &#8220;ownership&#8221; conventions which the guide outlines. Ownership over objects determines whether or not it is your responsibility to manage an object&#8217;s memory or not. Following this memory management etiquette allows your applications to work in conjunction with other objects and libraries and ensure they follow the accepted memory management procedures; they cover three main points about memory management for objects:</p>
<h2>1. Object Creation and Ownership</h2>
<blockquote><p>You own any object you create.<br />
You “create” an object using a method whose name begins with “alloc” or “new” or contains “copy” (for example, <code>alloc</code>, <code>newObject</code>, or <code>mutableCopy</code>).</p></blockquote>
<p>This is an important point for managing memory for objects in Cocoa; there is some ambiguity when using methods that return objects on whether you have to manage the memory for those returned objects, or whether this is done for you.</p>
<p>For example, take the <code>NSString</code> class. Several string creation methods exist, which seem to have counterparts, for example <code>initWithCharacters:length:</code> and <code>stringWithCharacters:length:</code>. But what&#8217;s the difference? Taking a look at the method declarations in more detail, you will see that <code>initWithCharacters:length:</code> has the method declaration:</p>
<pre class="prettyprint">- (id)initWithCharacters: (const unichar *)characters length: (NSUInteger)length;</pre>
<p>As with all Objective-C methods, the minus sign denotes that the method is an instance method, and in this way you must instantiate an <code>NSString</code> object to call <code>initWithCharacters:length:</code> upon. How do you do this? By first calling <code>alloc</code> on <code>NSString</code>, which is a &#8220;method whose name begins with “alloc” or “new” or contains “copy”&#8221;. As of this, if you create an <code>NSString</code> object using the <code>initWithCharacters:length:</code> method, you must memory manage that object yourself, since you take ownership of that object by creating it.</p>
<p>The method declaration of <code>stringWithCharacters:length:</code> is as so:</p>
<pre class="prettyprint">+ (id)stringWithCharacters: (const unichar *)chars length: (NSUInteger)length;</pre>
<p>The plus sign denotes a <em>class</em> method of <code>NSString</code> this time, and so when calling this method, you do not need to first instantiate an <code>NSString</code> object, instead calling it on <code>NSString</code> directly. In this way, it tells you that you do not need to memory manage the <code>NSString</code> returned, and this will be done for you (since the <code>NSString</code> is returned, it will be autoreleased).</p>
<h3>Naming conventions</h3>
<p>Naming conventions for creation methods in the Cocoa classes often follow patterns; methods that start with &#8220;init&#8221; are often custom implementations of <code>NSObject</code>&#8217;s <code>init</code> method, and so are instance methods which have to be called on an allocated instance of that class, and have to be memory managed. Creation methods which do not start with &#8220;init&#8221; are conventionally class methods, and so return autoreleased objects that don&#8217;t have to be memory managed.</p>
<h2>2. Releasing Created Objects</h2>
<p>The second item of the object ownership policy is:</p>
<blockquote><p>If you own an object, you are responsible for relinquishing ownership when you have finished with it.<br />
You relinquish ownership of an object by sending it a <code>release</code> message or an <code>autorelease</code> message (autorelease is discussed in more detail in “Delayed Release”). In Cocoa terminology, relinquishing ownership of an object is typically referred to as “releasing” an object.</p></blockquote>
<p>If you have created the object, as established by point #1, then <strong>it is your responsibility to release it</strong>. This is very important for the maintained stability of your application, because otherwise you will leak memory, which &#8211; especially for iPhone development &#8211; can affect the performance of your application. Even if it is a small amount of memory, which you may not perceive as being worth bothering about, it is good practice to make your application as efficient as possible.</p>
<h2>3. Memory management for objects you don&#8217;t create</h2>
<p>The third item of the object ownership policy is:</p>
<blockquote><p>If you do not own an object, you must not release it.</p></blockquote>
<p>This is important, because you can &#8220;overrelease&#8221; an object, since you did not retain it initially because you do not &#8220;own&#8221; it. This can cause the object to be deallocated prematurely, and can cause your application to crash if a message is then sent to the now redundant piece of memory.</p>
<h2>Taking ownership of objects</h2>
<p>According to point #1, if you do not create an object, then you should not memory manage it. However, what if you are returned an autoreleased object, but want to hold onto it? An autoreleased object will be released by the autorelease pool at the end of the current event, and so if you need to keep it for a longer period of time than this, then you will essentially have a bad pointer to memory that has been relinquished.</p>
<p>In this case, you must take ownership of the object that has been returned to you in a memory-managed state. To do so, simply call <code>retain</code> on the object. This will ensure that it is not deallocated, because you are explicitly specifying that you want to keep the object around until further notice. As long as other objects that have a hold on the object (if there are any) follow the memory management guidelines then the object will stick around for as long as you need it for:</p>
<pre class="prettyprint">
- (void)someFunction:(int)aNumber
{
    // Assume that 'string' is an instance variable; returns an autoreleased NSString
    string = [NSString stringWithFormat:@"Some number: %d", aNumber]; //Retain the string to take ownership so it won't be released
    [string retain];
}
</pre>
<p>Even though you didn&#8217;t create the object, now that you have taken ownership of the object in question, you <strong>must also release the object when you are done with it</strong> (following point #1) since you now have some form of ownership over it (whether that be full or partial).</p>
<h2>Core Foundation classes and memory management</h2>
<p>The Core Foundation classes have a similar ownership policy, as stated in the <a href="http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029">Memory Management Guide for Core Foundation</a>. This is similar to the Cocoa ownership policy:</p>
<blockquote><p>Core Foundation functions have names that indicate when you own a returned object:</p></blockquote>
<ul>
<li>Object-creation functions that have “Create” embedded in the name;</li>
<li>Object-duplication functions that have “Copy” embedded in the name.</li>
</ul>
<p>If you take ownership of a Core Foundation object, <strong>you must release it when you are finished with it using</strong> <code>CFRelease</code>.</p>
<p>As noted in the guide, if you are returned a Core Foundation object through a function other than one which has &#8220;Create&#8221; or &#8220;Copy&#8221; in the name, you do not take ownership of it, and do not need to memory manage it. However, similar to the Cocoa classes, you can take ownership of  a Core Foundation object by calling <code>CFRetain</code> on the object. Once again, <strong>do not forget to call</strong> <code>CFRelease</code> <strong>once you are done with the object.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/182/cocoa-memory-management-etiquette/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcoding made easy</title>
		<link>http://perspx.com/blog/archives/44/xcoding-made-easy/</link>
		<comments>http://perspx.com/blog/archives/44/xcoding-made-easy/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 20:10:54 +0000</pubDate>
		<dc:creator>Perspx</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://oneinfinitemonkey.wordpress.com/?p=44</guid>
		<description><![CDATA[Xcode is Apple&#8217;s Integrated Development Environment for applications written for OS X or iPhone OS. With the increasing popularity for software written for both platforms, here are some useful features of Xcode that make coding using it a much smoother and easier process.
Keyboard Shortcuts
There are a plethora of keyboard shortcuts in Xcode to perform common tasks associated with various aspects  ... ]]></description>
			<content:encoded><![CDATA[<p>Xcode is Apple&#8217;s Integrated Development Environment for applications written for OS X or iPhone OS. With the increasing popularity for software written for both platforms, here are some useful features of Xcode that make coding using it a much smoother and easier process.</p>
<h2>Keyboard Shortcuts</h2>
<p>There are a plethora of keyboard shortcuts in Xcode to perform common tasks associated with various aspects of the development tool. Here is a handy chart of all the Xcode keyboard shortcuts available (note that <a href="http://www.1729.us/"></a>this chart was created by <a href="http://www.1729.us/" target="_blank">Colin Wheeler</a>):</p>
<p><a href="http://www.1729.us/xcode/Xcode%20Shortcuts.png"><img class="aligncenter size-full wp-image-779" title="Xcode Keyboard Shortcuts" src="http://perspx.com/wp-content/uploads/2009/06/xcode_keyboard_shortcuts1.jpg" alt="" width="200" height="207" /></a></p>
<h2>All-In-One View</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/06/xcode_allinone_view.png"><img class="size-medium wp-image-781 alignleft" title="All in one View" src="http://perspx.com/wp-content/uploads/2009/06/xcode_allinone_view-300x204.png" alt="" width="300" height="204" /></a></p>
<p>In the Xcode preferences, the default layout is, oddly enough, the <em>Default</em> layout. This is better set to <em>All-In-One</em>, since it adds extra panes to the main window, such as the <em>Page</em> toolbar item, which allows you to switch between the Project and Debug modes with one click, in the same main window. Also, a tabbed menu is added above the editor window, with tabs for <em>Detail</em>, <em>Project Find</em>, <em>SCM Results</em> and <em>Build</em>, which make it easier to access different windows within your project, keeping them within the same workspace. To change the layout to <em>All-In-One</em>, open up the Xcode preferences (⌘+,) and in the <em>General</em> preferences, change the <em>Layout</em> preference to <em>All-In-One</em>.</p>
<h2>The #pragma mark directive</h2>
<p>The <code>#pragma mark</code> directive is very useful in organising implementation files, especially those with a large number of methods. It can be placed anywhere in the source files, and is used as a way of grouping common methods. It takes the form:</p>
<p><code>#pragma mark &lt;Label&gt;</code></p>
<p>Where &lt;<code>Label&gt;</code> is the name you want to associate. For example:</p>
<p><code><br />
#pragma mark Drawing- (void)drawRect:(NSRect)rect {<br />
// Drawing code here.<br />
}//... other methods here, if necessary</p>
<p></code></p>
<p>and it allows you to group together methods in the Project Symbols list; with any method signature following the group name being listed underneath the group title you have assigned.</p>
<p><img class="aligncenter size-medium wp-image-782" title="Xcode function list" src="http://perspx.com/wp-content/uploads/2009/06/function_list-300x241.png" alt="" width="300" height="241" /></p>
<p>Clicking on any of the method names selects the method declaration in the file and scrolls down to that point; in this way it is easy to navigate around the implementation files, even if they contain a lot of code or methods.</p>
<h2>Finding APIs in the documentation</h2>
<p>When writing code in Xcode, it is not uncommon for you to need to take a look at the documentation for a particular symbol, be that method, class, or even data types, for example. You could do this by going to <em>Help &gt; Documentation</em> and then typing in the name of the symbol into the search field, and then hitting return.</p>
<p>However, there is an easier way. In your source file, double-click on the word that you want to look up in the docs, whilst holding down the <strong>⌥ (option)</strong><strong> key</strong>. This will then open up the documentation window, filling the search field in with the word that you want to look up.</p>
<h2>Finding declarations</h2>
<p>It may also be the case that you want to look up the declarations for symbols, as defined in the headers. For example, you may wish to find the interface for <code>NSObject</code> or the typedef for <code>NSUInteger</code>. Again, this is easily accomplished. In your source file, double-click on the symbol that you want to find the declaration for, whilst holding down the <strong>⌘ (command) key</strong>.</p>
<h2>Bookmarking Code</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/06/xcode_add_bookmark1.png" target="_blank"><img class="size-medium wp-image-783 alignleft" title="xcode_add_bookmark" src="http://perspx.com/wp-content/uploads/2009/06/xcode_add_bookmark1-300x164.png" alt="" width="300" height="164" /></a></p>
<p>Xcode allows you to add bookmarks to your project, not just of source files themselves, but even lines <em>within</em> the files. These bookmarks get added to the <em>Bookmarks</em> section in the <em>Groups &amp; Files</em> pane. To add a bookmark, place the text caret on the line which you want to bookmark, and select <em><strong>Edit &gt; Add to Bookmarks</strong></em> or (<strong>⌘+D</strong>); the name of the file the line originates from, and the line number will be displayed as the bookmark name, although this can be renamed by clicking on the bookmark name.</p>
<h2>Go to Counterpart</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/06/go_to_counterpart1.png"><img class="size-medium wp-image-784 alignleft" title="Go to counterpart" src="http://perspx.com/wp-content/uploads/2009/06/go_to_counterpart1-300x191.png" alt="" width="300" height="191" /></a></p>
<p>Classes are one of the major additions to the Objective-C superset of C, and are used frequently in. There exists class interface and implementation files for any class, and it is frequent to switch between both, such as when declaring a method in the interface, then implementing it in the implementation. There is a button which makes switching between the two easier, titled <strong>Go to Counterpart</strong>; clicking on it will change the editor window to the implementation for that class, if working within the class interface file, or the interface if working within the implementation file.</p>
<p>Whether the counterpart is opened in the same editor window or another editor window is determined in the Xcode <em>General</em> preferences, with the &#8220;Open counterparts in same editor&#8221; checkbox.</p>
<h2>Simple Housekeeping</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/06/organising_files1.png"><img class="alignright size-medium wp-image-785" title="Organising files" src="http://perspx.com/wp-content/uploads/2009/06/organising_files1-178x299.png" alt="" width="178" height="299" /></a>When dealing with Xcode projects, the number of files present can quickly mount up, whether that be source code, resources, NIBs or any other files that your project uses. When adding files to the project, Xcode doesn&#8217;t add them to any particular directory in the Groups &amp; Files list, so it is up to you to do this. Note that the directory structure in the <em>Groups &amp; Files</em> list is purely virtual &#8211; any movement of files within the hierarchy has no physical effect on disk. To add groups to the list, simply right click in the window and select <em><strong>Add &gt; New Group</strong></em>, and once added, groups can be dragged around like you would in a Finder window.<em> </em>Here is a summary of the various groups and files within the project subdirectory:</p>
<ol>
<li><strong>Classes:</strong> as it says on the tin, place class interface (.h) and implementation (.m) files in here. It may be useful to group class files based on their purpose, for example naming groups <em>Controllers</em> or <em>Models</em>, etc to make it easier to find the source files when you need them.</li>
<li><strong>Other sources</strong>: this group is for source files that do not declare classes; main.m is here by default. Since most source files deal with classes, there are usually not so many files in here, unless you are creating a non-AppKit based application, such as a Foundation Tool.</li>
<li><strong>Resources</strong>: where all the project resources are placed, be that NIBs, or images, for example, this is the place to keep it. It may be useful to group resources based on their function, especially NIBs since in larger projects the number of these can quickly mount up.</li>
<li><strong>Frameworks:</strong> this is where the frameworks that your project uses are. Xcode adds the <em>Cocoa</em>, <em>AppKit</em> and <em>Foundation</em> frameworks for you when a project is created, but if you need to link against others, this is the place to put them. If a lot of frameworks are being linked to, it would be best to create extra subdirectories to organise the linked frameworks. Frameworks can be added by right clicking in the <em>Groups &amp; Files</em> window and selecting <em>Add &gt; Existing Frameworks..</em></li>
<li><strong>Products:</strong> these are the products of building the target(s). Normally there is only one product, your .app application file, so extra organisation of this subdirectory is not usually particularly necessary.</li>
</ol>
<h2>Debugging</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/06/debug_preferences1.png"><img class="size-medium wp-image-786 alignright" title="Debug preferences" src="http://perspx.com/wp-content/uploads/2009/06/debug_preferences1-300x203.png" alt="" width="300" height="203" /></a></p>
<p>A lot of time is often spent debugging your application. The interface can be made more straightforward in the <em>Debugging</em> pane of the Xcode preferences. There is a popup menu labelled <em>On Start:</em> this is how the workspace will change when debugging of your application begins. Its default is <em>Do Nothing</em>, however selecting <em>Show Console</em>,<em> Show Debugger </em>or <em>Show Console and Debugger</em> are useful so that when you begin to debug your application the workspace can update itself accordingly to make debugging a more straightforward process.</p>
<h2>Start with Performance Tool..</h2>
<p><a href="http://perspx.com/wp-content/uploads/2009/06/start_performance_tool1.png"><img class="size-medium wp-image-787 alignleft" title="Start with performance tool" src="http://perspx.com/wp-content/uploads/2009/06/start_performance_tool1-300x224.png" alt="" width="300" height="224" /></a></p>
<p>The Xcode Tools do not encompass simply Xcode and Interface Builder; there are a few other other tools bundled with the package that are useful when testing projects, such as Instruments and Shark. Instead of having to build your application every time then manually loading it into the designated tool, it can be done from the <em>Run</em> menu. From <em>Run &gt; Start With Performance Tool</em>, you can load your application into Shark, MallocDebug or one of the Instruments templates, such as <em>Leaks</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://perspx.com/blog/archives/44/xcoding-made-easy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
