<?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>Long Pointers &#187; Cocoa/Objective-C</title>
	<atom:link href="http://www.matthew-long.com/category/engineering-journal/cocoaobjective-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.matthew-long.com</link>
	<description>Matt Long's Blog About Programming and Stuff</description>
	<lastBuildDate>Fri, 08 May 2009 20:53:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scott Stevenson on Writing Copy For Product Pages</title>
		<link>http://www.matthew-long.com/2008/03/26/scott-stevenson-on-writing-copy-for-product-pages/</link>
		<comments>http://www.matthew-long.com/2008/03/26/scott-stevenson-on-writing-copy-for-product-pages/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 00:11:11 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2008/03/26/scott-stevenson-on-writing-copy-for-product-pages/</guid>
		<description><![CDATA[Scott Stevenson, webmaster and author for his Cocoa development site Cocoa Dev Central and weblog Theocacao, has written a new post on writing copy for product pages. The &#8216;keep it simple&#8217; meme is the gist, but read what he has to say.
This is quite interesting to me as I have a product release that is [...]]]></description>
			<content:encoded><![CDATA[<p>Scott Stevenson, webmaster and author for his Cocoa development site <a href="http://cocoadevcentral.com/">Cocoa Dev Central</a> and weblog <a href="http://theocacao.com/">Theocacao</a>, has written a new post on <a href="http://theocacao.com/document.page/562">writing copy for product pages</a>. The &#8216;keep it simple&#8217; meme is the gist, but read what he has to say.</p>
<p>This is quite interesting to me as I have a product release that is imminent. Well, maybe not imminent. The code is almost done. Now I need to write some copy, figure out the PayPal IPN, incorporate Sparkle&#8230; etc. etc. Ok. Nevermind. It&#8217;s not imminent.</p>
<p>Anyhow, thanks for the post Scott. This is good stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2008/03/26/scott-stevenson-on-writing-copy-for-product-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Animation Tutorial: Dashboard Effect</title>
		<link>http://www.matthew-long.com/2008/03/16/core-animation-tutorial-dashboard-effect/</link>
		<comments>http://www.matthew-long.com/2008/03/16/core-animation-tutorial-dashboard-effect/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 22:49:16 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Apple Computer]]></category>
		<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2008/03/16/core-animation-tutorial-dashboard-effect/</guid>
		<description><![CDATA[I just finished another Core Animation tutorial and posted it at CIMGF over the weekend. This was a pretty fun one. I wanted to duplicate the effect of the Dashboard widgets flying in and out from off screen and this is what I came up with. Take a look and let me know what you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cimgf.com/2008/03/15/core-animation-tutorial-dashboard-effect/"><img src="http://www.cimgf.com/wp-content/uploads/2008/03/dashboardeffect.thumbnail.jpg" border="0" align="left"></a>I just finished another Core Animation tutorial and posted it at <a href="http://www.cimgf.com/">CIMGF</a> over the weekend. This was a pretty fun one. I wanted to duplicate the effect of the Dashboard widgets flying in and out from off screen and this is what I came up with. Take a look and let me know what you think. <a href="http://www.cimgf.com/2008/03/15/core-animation-tutorial-dashboard-effect/">Core Animation Tutorial: Dashbaord Effect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2008/03/16/core-animation-tutorial-dashboard-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Animation Tutorial: Wizard Dialog with Transitions</title>
		<link>http://www.matthew-long.com/2008/03/04/core-animation-tutorial-wizard-dialog-with-transitions/</link>
		<comments>http://www.matthew-long.com/2008/03/04/core-animation-tutorial-wizard-dialog-with-transitions/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 21:45:31 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Apple Computer]]></category>
		<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Engineering Journal]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2008/03/04/core-animation-tutorial-wizard-dialog-with-transitions/</guid>
		<description><![CDATA[Marcus can really crank these articles out. His latest demonstrates how to create a Wizard interface with next and previous buttons, however, this is not your average every day Wizard interface. This one employs Core Animation. When you click the next or previous buttons, you&#8217;ll see that the next view slides in from the right [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.matthew-long.com/wp-content/uploads/2008/03/wizard-tutorial.jpg' title='Wizard Tutorial'><img src='http://www.matthew-long.com/wp-content/uploads/2008/03/wizard-tutorial.thumbnail.jpg' alt='Wizard Tutorial' align="left" style="margin:5px;" /></a>Marcus can really crank these articles out. His latest demonstrates how to create a Wizard interface with next and previous buttons, however, this is not your average every day Wizard interface. This one employs Core Animation. When you click the next or previous buttons, you&#8217;ll see that the next view slides in from the right or left depending on which you clicked. Take a look at his latest tutorial post: <a href="http://www.cimgf.com/2008/03/03/core-animation-tutorial-wizard-dialog-with-transitions/">Core Animation Tutorial: Wizard Dialog with Transitions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2008/03/04/core-animation-tutorial-wizard-dialog-with-transitions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Animation Tutorial: Window Shake Effect</title>
		<link>http://www.matthew-long.com/2008/02/28/core-animation-tutorial-window-shake-effect/</link>
		<comments>http://www.matthew-long.com/2008/02/28/core-animation-tutorial-window-shake-effect/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 17:49:51 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Apple Computer]]></category>
		<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[core animation tutorial]]></category>
		<category><![CDATA[shake window]]></category>
		<category><![CDATA[vibrate window]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2008/02/28/core-animation-tutorial-window-shake-effect/</guid>
		<description><![CDATA[Marcus and I have started to have NSCoder Nights on Monday&#8217;s at Panera Bread on Powers near S. Carefree. We&#8217;ve been working to try to learn how to do certain OS X Leopard animation effects using Core Animation. The first challenge we took on was figuring out how to shake a window back and forth [...]]]></description>
			<content:encoded><![CDATA[<p>Marcus and I have started to have <a href="http://nscodernight.com/">NSCoder Nights</a> on Monday&#8217;s at Panera Bread on Powers near S. Carefree. We&#8217;ve been working to try to learn how to do certain OS X Leopard animation effects using Core Animation. The first challenge we took on was figuring out how to shake a window back and forth to indicate that the user has entered the wrong password in the login window. OS X does this when you try to login and enter your password incorrectly. If you&#8217;ve never seen it before, you either don&#8217;t have manual login enabled, or you&#8217;ve never entered your password incorrectly.</p>
<p>Anyhow, the article is short, but it has an XCode project that you can download and use. Take a look at the post, <a href="http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/">Core Animation Tutorial: Window Shake Effect</a> and let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2008/02/28/core-animation-tutorial-window-shake-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSOperation Example</title>
		<link>http://www.matthew-long.com/2008/02/23/nsoperation-example/</link>
		<comments>http://www.matthew-long.com/2008/02/23/nsoperation-example/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 07:03:35 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Apple Computer]]></category>
		<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Engineering Journal]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[mac programming]]></category>
		<category><![CDATA[NSOperation]]></category>
		<category><![CDATA[NSOperationQueue]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2008/02/23/nsoperation-example/</guid>
		<description><![CDATA[I just finished writing a new article for Cocoa Is My Girlfriend. I am building on the work Marcus did on his first article called Cocoa Tutorial: NSOperation and NSOperationQueue. In my article I&#8217;m taking a slightly more practical approach where I provide a flicker free method for grabbing images from a currently playing QuickTime [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.cimgf.com/wp-content/uploads/2008/02/picture-14.thumbnail.png" align="left" style="margin:5px;">I just finished writing a new article for <a href="http://www.cimgf.com/">Cocoa Is My Girlfriend</a>. I am building on the work Marcus did on his first article called <a href="http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/">Cocoa Tutorial: NSOperation and NSOperationQueue</a>. In my article I&#8217;m taking a slightly more practical approach where I provide a flicker free method for grabbing images from a currently playing QuickTime movie. The NSOperation grabs the image data from the movie and saves it out to a folder in the filesystem specified by the user.</p>
<p>I think it is pretty cool. I hope it will help others see the power and flexibility of NSOperation and NSOperationQueue.</p>
<p>Read the new article, <a href="http://www.cimgf.com/2008/02/23/nsoperation-example/">NSOpeartion Example, here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2008/02/23/nsoperation-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa Tutorial: NSOperation and NSOperationQueue</title>
		<link>http://www.matthew-long.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/</link>
		<comments>http://www.matthew-long.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/#comments</comments>
		<pubDate>Sun, 17 Feb 2008 02:46:01 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Apple Computer]]></category>
		<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Engineering Journal]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/</guid>
		<description><![CDATA[I just finished helping Marcus post an article on our new site Cocoa Is My Girlfriend, a site dedicated to providing blog posts and tutorials on how to develop applications using Objective-C and Cocoa on the Macintosh.
This first post is on how to use the new threading objects found in Mac OS X Leopard (10.5) [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished helping <a href="http://www.zarrastudios.com">Marcus</a> post an article on our new site <a href="http://www.cimgf.com/">Cocoa Is My Girlfriend</a>, a site dedicated to providing blog posts and tutorials on how to develop applications using Objective-C and Cocoa on the Macintosh.</p>
<p>This first post is on how to use the new threading objects found in Mac OS X Leopard (10.5) called NSOperation and NSOperationQueue. They provide a really simple and robust way to do multi-threaded programming. <a href="http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/">Take a look at the post and let us know what you think.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Satisfaction Guaranteed</title>
		<link>http://www.matthew-long.com/2008/01/11/satisfaction-guaranteed/</link>
		<comments>http://www.matthew-long.com/2008/01/11/satisfaction-guaranteed/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 22:16:07 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Apple Computer]]></category>
		<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Engineering Journal]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2008/01/11/satisfaction-guaranteed/</guid>
		<description><![CDATA[So I&#8217;ve been using the NetBeans IDE v6 to do some Java development. I&#8217;ve been pretty happy with it so far. It has a nice set of project templates. It allows you to run and test web apps directly and at $0 dollars you can&#8217;t beat the price.
I loaded the application today and here is [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been using the NetBeans IDE v6 to do some Java development. I&#8217;ve been pretty happy with it so far. It has a nice set of project templates. It allows you to run and test web apps directly and at $0 dollars you can&#8217;t beat the price.</p>
<p>I loaded the application today and here is what I was greeted with:<br />
<img src='http://www.matthew-long.com/wp-content/uploads/2008/01/picture-1.png' alt='Bad Netbeans!' /></p>
<p>Now, I suppose you could make the case that since it&#8217;s a free application, I should be obliged to take their survey, but I don&#8217;t recall agreeing to that. Just like most people, I didn&#8217;t read the license agreement so maybe I did agree to it, but what&#8217;s funny is that they want me to express my satisfaction with an application that has, for the first time since I started using it mind you, done that which is one of the most likely ways to cause dissatisfaction. They gave me two options and neither of them are useful to me.</p>
<p>Netbeans is cross-platform which means you&#8217;re going to have some hold-over ideas from other platforms, namely Windows. Since I work on a Mac, this also seemed very unfamiliar. Mac apps don&#8217;t bother you with stupid dialog boxes (that often) and when they do, they normally give you a way out. This dialog does not.</p>
<p>Call me crazy, but I don&#8217;t think a third option that says &#8220;No thanks. I don&#8217;t ever want to take a survey&#8221;, or even simply &#8220;Cancel&#8221; would suffice for the moment. That&#8217;s basically what &#8220;Remind Later&#8221; does, but when labeled that way, I realize that I should deal with this in a permanent way <em>in order to be left alone</em>, but the only permanent way is to choose the other option, &#8220;Go To Survey&#8221;. Now, I realize I don&#8217;t have to take the survey once I&#8217;m at the site, however, I am now less satisfied with the application because it is bugging me to take a survey and tell the company that I&#8217;m not satisfied because they bugged me about taking a survey. (I&#8217;m dizzy now) So I&#8217;m going to clue them in without taking the survey. Hello, Netbeans people. Yes. Here&#8217;s one way to guarantee my satisfaction&#8211;leave me alone!!</p>
<p>So this is just a rant and me complaining. It&#8217;s not that big a deal, but I would take this opportunity to say that if you are a new Mac developer coming from the Windows world where forcing users into choices they don&#8217;t want is the order of the day, just get over that notion now. Don&#8217;t start building Mac apps that do this. Please. It doesn&#8217;t help anyone. I think Mac users are generally happier people. I think it&#8217;s because their apps are unobtrusive. Leave your users alone. They&#8217;ll let you know if you need to fix or change something.</p>
<p><strong>Update:</strong> Just got contacted by Gregg Sporar who works for Sun (see the comments). He says this has been fixed in Netbeans 6.1. Cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2008/01/11/satisfaction-guaranteed/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cocoa/Objective-C FTP Library/Framework</title>
		<link>http://www.matthew-long.com/2007/11/24/cocoaobjective-c-ftp-libraryframework/</link>
		<comments>http://www.matthew-long.com/2007/11/24/cocoaobjective-c-ftp-libraryframework/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 22:06:42 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Apple Computer]]></category>
		<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Engineering Journal]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2007/11/24/cocoaobjective-c-ftp-libraryframework/</guid>
		<description><![CDATA[Why is this so hard to find on the web? I did a search for an FTP library on google that would work in Cocoa and found nothing. Then I asked Marcus if he knew of a good library and he simply said, &#8220;the ConnectionKit&#8220;. 
Sure enough, I downloaded the code and built it (you&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>Why is this so hard to find on the web? I did a search for an FTP library on google that would work in Cocoa and found nothing. Then I asked <a href="http://www.zarrastudios.com/ZDS/Blog/Blog.html">Marcus</a> if he knew of a good library and he simply said, &#8220;the <a href="http://opensource.utr-software.com/connection/">ConnectionKit</a>&#8220;. </p>
<p>Sure enough, I downloaded the code and built it (you&#8217;ll need to run the svn command <a href="http://opensource.utr-software.com/connection/download.html">on this page</a> from Terminal.app to get the source. Then open Connection.xcodeproj in XCode and build). Then I incorporated it into a simple demo app and I was simply shocked. How can this amazing library be so difficult to find on the web. It is incredibly powerful and stable!! It makes it simple to create your own FTP client application in no time.</p>
<p>What&#8217;s also cool about it is that it it doesn&#8217;t stop with just FTP. It supports numerous network connection protocols including FTP, FTP over SSL, SFTP (secure FTP), .mac, WebDAV, secure WebDAV, Amazon S3, NNTP, and HTTP.</p>
<p>I personally only need it for its FTP capabilities, so my demo app only does FTP, but you can see how simple it is to use from the application and could easily apply any of the other protocols.</p>
<p>Get my demo application here: <a id="p78" href="http://www.matthew-long.com/wp-content/uploads/2007/11/ConnectionTest.zip">ConnectionTest.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2007/11/24/cocoaobjective-c-ftp-libraryframework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Translate DOM Element In WebView To View Coordinates</title>
		<link>http://www.matthew-long.com/2007/11/19/translate-dom-element-in-webview-to-view-coordinates/</link>
		<comments>http://www.matthew-long.com/2007/11/19/translate-dom-element-in-webview-to-view-coordinates/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 04:15:30 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Engineering Journal]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2007/11/19/translate-dom-element-in-webview-to-view-coordinates/</guid>
		<description><![CDATA[I set out to figure out how to translate a DOM element in the WebView to a rectangle on the screen. I wanted to display visual cues when clicking on the web page that highlight the DOM element that was clicked.
After about a week of searching, it turns out the answer is pretty simple. The [...]]]></description>
			<content:encoded><![CDATA[<p>I set out to figure out how to translate a DOM element in the WebView to a rectangle on the screen. I wanted to display visual cues when clicking on the web page that highlight the DOM element that was clicked.</p>
<p>After about a week of searching, it turns out the answer is pretty simple. The WebView provides a method called <code>elementAtPoint()</code> which takes an <em>NSPoint</em> as it&#8217;s parameter. You simply need to intercept a mouse click event and obtain its <em>locationInWindow</em> and pass that to <code>elementAtPoint</code> which will return you an <em>NSDictionary</em>  containing several objects. The object you&#8217;re interested in can be obtained by calling <code>objectForKey</code> on the <em>NSDictionary</em> passing it the key <em>@&#8221;WebElementDOMNode&#8221;. Check to see that the object exists and then you can use it. I simply set the returned object to a <em>DOMNode</em> object which contains within it the magic variable called <em>boundingBox</em>. You now have your rectangle and know exactly where on the view the DOM element you clicked is being displayed. Here is some code to demonstrate:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Inside your mouse click event handler</span>
<span style="color: #a61390;">NSPoint</span> point <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>theEvent locationInWindow<span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>dict <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>webView elementAtPoint<span style="color: #002200;">:</span>point<span style="color: #002200;">&#93;</span>;
&nbsp;
DOMNode <span style="color: #002200;">*</span>node <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dict objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;WebElementDOMNode&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Make sure the node is not nil</span>
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> node <span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">NSRect</span> rect <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>node boundingBox<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">int</span> left <span style="color: #002200;">=</span> rect.origin.x;
	<span style="color: #a61390;">int</span> top <span style="color: #002200;">=</span> rect.origin.y;
	<span style="color: #a61390;">int</span> width <span style="color: #002200;">=</span> rect.size.width;
	<span style="color: #a61390;">int</span> height <span style="color: #002200;">=</span> rect.size.height;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Do something with the coordinates</span>
	<span style="color: #11740a; font-style: italic;">// ...</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>At that point you can do what you would like. I want to draw an overlay rectangle to highlight the DOM element on the screen, but from what I understand, drawing over the WebView may be a bit of a challenge. I&#8217;ve experimented with just adding another div with absolute positioning to the DOMDocument to act as my rectangle overlay, but I&#8217;ve had some issues with it. I&#8217;ll keep you posted here on my progress.</p>
<p>Also, you should probably know that in order to intercept a mouse click when you have a <em>WebView</em> in your window, you&#8217;ll have to subclass <em>NSWindow</em> and override <code>- (void)sendEvent:(NSEvent *)theEvent</code> and filter for left mouse clicks. Let me know if you need a further explanation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2007/11/19/translate-dom-element-in-webview-to-view-coordinates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XCode 3.0 Tutorial</title>
		<link>http://www.matthew-long.com/2007/11/09/xcode-30-tutorial/</link>
		<comments>http://www.matthew-long.com/2007/11/09/xcode-30-tutorial/#comments</comments>
		<pubDate>Fri, 09 Nov 2007 21:30:05 +0000</pubDate>
		<dc:creator>perlmunger</dc:creator>
				<category><![CDATA[Apple Computer]]></category>
		<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Engineering Journal]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.matthew-long.com/2007/11/09/xcode-30-tutorial/</guid>
		<description><![CDATA[



I&#8217;ve seen numerous posts on different discussion boards posted by new Mac users wanting to learn to write code for the Mac. The main complaint is that Interface Builder is too different from the existing documentation, including Aaron Hillegass&#8217;s excellent Cocoa Programming for Mac OS X (which actually remains very relevant, by the way. You [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-3030718858857706";
/* 468x15, created 2/7/08 */
google_ad_slot = "7586423078";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>I&#8217;ve seen numerous posts on different discussion boards posted by new Mac users wanting to learn to write code for the Mac. The main complaint is that Interface Builder is too different from the existing documentation, including Aaron Hillegass&#8217;s excellent <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2FCocoa-Programming-Mac-OS-2nd%2Fdp%2F0321213149%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1195939800%26sr%3D8-1&#038;tag=longpoin-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325">Cocoa Programming for Mac OS X</a><img src="http://www.assoc-amazon.com/e/ir?t=longpoin-20&amp;l=ur2&amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> (which actually remains very relevant, by the way. You can wait for some updated books to come out, but Aaron&#8217;s book still provides a lot of concepts and even methods that apply. You just need to know what&#8217;s changed in XCode 3 and Objective-C 2). So, I&#8217;m going to do a quick tutorial here. FULL DISCLOSURE: I learned this from <a href="http://www.zarrastudios.com/ZDS/Blog/Blog.html">Marcus Zarra</a>, so credit where credit is due. ;-)</p>
<p>Here are some points that you should keep in mind before moving ahead:</p>
<ul>
<li><strong>Don&#8217;t use Interface Builder to generate code</strong>. Create your code in XCode and let Interface Builder work with it. This isn&#8217;t absolutely necessary, but as Marcus told me, it&#8217;s just easier to get in this habit as the XCode 2 method of creating your controller, instantiating it, and generating your code files from Interface Builder simply isn&#8217;t available in the same way in XCode 3.0. I&#8217;ve come to see what Marcus is saying. It makes sense, but you&#8217;ll have to get into the process yourself to fully understand it. We&#8217;ll get to that in a minute.</li>
<p></p>
<li><strong>Understanding Cocoa programming is much simpler if you learn MVC</strong>. You can probably step through code examples and figure some things out without learning MVC (Model, View, Controller), but I wouldn&#8217;t recommend it. Go Google it and read up on it.
<p>I will say as an introduction to it for those who are not familiar that it should probably be called <strong>(Model <--> Controller <--> View)</strong> or <strong>(View <--> Controller <--> Model)</strong> as the controller always sits between the other two. Your controller is either telling your model to update its data or it is telling the view to update its display. That&#8217;s the crux of the whole paradigm. The details run much deeper, but that&#8217;s how I would nutshell it for you.</li>
</ul>
<h1>Create Your Application</h1>
<p>Let&#8217;s get started. Create a Cocoa Application using the following steps:</p>
<ol>
<li>Select <strong>File > New Project&#8230;</strong> and choose <em>Cocoa Application</em> in the ensuing dialog. Click <strong>Next</strong></li>
<p></p>
<li>Enter &#8216;FirstApp&#8217; as the project name. Click <strong>Finish</strong></li>
</ol>
<p>You should see a project workspace like the following:<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_workspace.png" title="FirstApp Workspace"><img id="image54" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_workspace.thumbnail.png" alt="FirstApp Workspace" /></a></p>
<p>The next thing you should do is create a class to act as your controller or delegate.</p>
<h1>Delegate == Controller</h1>
<p>The words delegate and controller can be used synonymously. You&#8217;ll see later that we delegate the work of the different controls we create in Interface Builder to a delegate or controller class. This should all make perfect sense momentarily. First, create your controller/delegate class using the following steps:</p>
<ol>
<li><strong>Option-Click</strong> on the <em>Classes</em> folder in your workspace and select &#8216;Add File&#8230;&#8217;<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_create_delegate.png" title="Add File"><img id="image55" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_create_delegate.thumbnail.png" alt="Add File" /></a></li>
<li>Choose <strong>Object-C Class</strong> in the ensuing dialog and click <strong>Next</strong><br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_new_file.png" title="New File Dialog"><img id="image56" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_new_file.thumbnail.png" alt="New File Dialog" /></a></li>
<li>Name the file &#8216;AppDelegate.m&#8217; and click <strong>Finish</strong><br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_new_objc_class.png" title="New Objectiv-C Class"><img id="image57" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_new_objc_class.thumbnail.png" alt="New Objectiv-C Class" /></a></li>
<li>A new code window will display with your &#8216;AppDelegate&#8217; interface code (.h file). Add an outlet for a text field and a label, and an action to the code so that it looks like this:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> AppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
	IBOutlet <span style="color: #400080;">NSTextField</span> <span style="color: #002200;">*</span>textField;
	IBOutlet <span style="color: #400080;">NSTextField</span> <span style="color: #002200;">*</span>label;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>clickButton<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

</li>
<p></p>
<li>Now switch over to your implementation file for &#8216;AppDelegate&#8217; (.m file). Add the <em>clickButton</em> implementation code so that the file looks like this:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> AppDelegate
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>clickButton<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;
<span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>
We will actually add some code to do something in the <em>clickButton</em> handler, but first we need to hook it up to the user interface in Interface Builder.
</li>
<p>
</ol>
<h1>Interface Builder And Controller/Delegate Implementation</h1>
<p>Now that you&#8217;ve specified the outlets&#8211;two <em>NSTextField</em>s, one a text field and one a label in this case&#8211;and an action called <em>clickButton</em>, you will see these items available for connecting to the UI in Interface builder. Let&#8217;s open Interface Builder and make the connections we need using the following steps:</p>
<ol>
<li>In your XCode workspace, expand the folder in the tree view called <strong>NIB Files</strong> and double click the file called &#8216;MainMenu.nib&#8217;. This will open the <em>nib</em> file in Interface Builder<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_select_nib.png" title="Select NIB File in Workspace"><img id="image59" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_select_nib.thumbnail.png" alt="Select NIB File in Workspace" /></a>
</li>
<p></p>
<li>Once Interface Builder loads select the <em>NSObject</em> item and drag it into the &#8216;MainMenu.nib&#8217; window.<br />
<img id="image61" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_add_controller.png" alt="Add NSObject" /><br />
Then rename it to &#8216;AppDelegate&#8217;<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_ib_appdelgate.png" title="Interface Builder AppDelegate"><img id="image62" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_ib_appdelgate.thumbnail.png" alt="Interface Builder AppDelegate" /></a>
</li>
</ol>
<h1>Making Connections (Pay Attention Here)</h1>
<p>These next two steps are critical for your understanding. You now need to tell Interface Builder the following:</p>
<ul>
<li><strong>What object you want to use as a <em>File&#8217;s Owner</em></strong>. You will delegate actions to a delegate/controller object. You tell the application which object to use by setting the <em>File&#8217;s Owner</em> delegate.</li>
<p></p>
<li><strong>What type of object this delegate is</strong>. Before you can specify which object to use as the <em>File&#8217;s Owner</em> you have to set the object type. A regular NSObject doesn&#8217;t provide any implementation for your app. You need to tell Interface Builder that you want your NSOBject to actually be an object of type &#8216;AppDelegate&#8217;.
</ul>
<p>You can achieve this by completing the following steps:</p>
<ol>
<li>If you haven&#8217;t already, open the <em>Inspector</em> in Interface Builder by selecting <strong>Tools > Inspector</strong></li>
<p></p>
<li>Click on your NSObject that you named &#8216;AppDelegate&#8217; and then click on the <em>Identity</em> tab in the inspector.</li>
<p></p>
<li>Change the class to type &#8216;AppDelegate&#8217; which will be available in Interface Builder as it has been able to obtain the class information from XCode.<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_ib_set_delegate_class.png" title="Set Delegate Class"><img id="image63" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_ib_set_delegate_class.thumbnail.png" alt="Set Delegate Class" /></a></p>
<p>You should also notice at this point in the <em>Class Actions</em> and <em>Class Outlets</em> sections of the Inspector, your action, <em>clickButton:</em> and your outlet, the <em>NSTextField</em> are now visible. We&#8217;ll hook those up in just a minute.</li>
<p></p>
<li><strong>Control-Click</strong> the <em>File&#8217;s Owner</em> object in the &#8216;MainMenu.nib&#8217; window and drag it to the &#8216;AppDelegate&#8217; object.<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_ib_set_files_owner.png" title="Set File's Owner"><img id="image65" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_ib_set_files_owner.thumbnail.png" alt="Set File's Owner" /></a><br />
<br />
A pop-up list will display. Select <em>delegate</em>.<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_set_files_owner_delgate.png" title="Set File's Owner Delegate"><img id="image66" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_set_files_owner_delgate.thumbnail.png" alt="Set File's Owner Delegate" /></a><br />

</li>
</ol>
<h1>Design The User Interface</h1>
<p>Now you simply need to add the controls to the main window in Interface Builder and then we can connect the <em>action</em> and <em>outlet</em> accordingly. To finish the interface, complete the following steps:</p>
<ol>
<li>Drag a <em>TextField</em>, a <em>Label</em>, and a <em>Button</em> to the main window so that the user interface looks like the screenshot below:<br />
<img id="image67" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_main_window.png" alt="Application Main Window Design" />
</li>
<li><strong>Control-Click</strong> and drag from the <em>Button</em>to your &#8216;AppDelegate&#8217; object in the &#8216;MainMenu.nib&#8217; window.<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_set_button_delegate.png" title="Set Button Delegate"><img id="image68" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_set_button_delegate.thumbnail.png" alt="Set Button Delegate" /></a><br />
A pop-up will display. Select <em>clickButton:</em><br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_set_button_action.png" title="Set Button Action"><img id="image69" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_set_button_action.thumbnail.png" alt="Set Button Action" /></a>
</li>
<li><strong>Control-Click</strong> the &#8216;AppDelegate&#8217; object and drag it to the text field in the main form.<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_connect_text_field.png" title="Connect Text Field"><img id="image70" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_connect_text_field.thumbnail.png" alt="Connect Text Field" /></a><br />
A pop-up will display. Select <em>textField</em><br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_select_text_field.png" title="Select Text Field"><img id="image71" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_select_text_field.thumbnail.png" alt="Select Text Field" /></a>
</li>
<li><strong>Control-Click</strong> the &#8216;AppDelegate&#8217; object and drag it to the label in the main form.<br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_connect_label.png" title="Connect Label"><img id="image72" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_connect_label.thumbnail.png" alt="Connect Label" /></a><br />
<br />
A pop-up will display. Select <em>label</em><br />
<a class="imagelink" href="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_select_label.png" title="Select Label"><img id="image73" src="http://www.matthew-long.com/wp-content/uploads/2007/11/first_app_select_label.thumbnail.png" alt="Select Label" /></a><br />

</li>
</ol>
<p>That&#8217;s it for Interface Builder. You can quit interface builder and return to XCode. We have one more piece of code to add and then our application will be finished.</p>
<h1>Finishing Up</h1>
<p>When the button is clicked, it will simply grab the text from the text field and place it into the label. That&#8217;s all the application does. Here&#8217;s the code you need. Just make your implementation in the &#8216;AppDelegate.m&#8217; file look like this:<br />
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> AppDelegate
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>clickButton<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>textField stringValue<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>label setStringValue<span style="color: #002200;">:</span>text<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>Now all you need to do is click &#8220;Build and Go&#8221;. When the application runs, type some text into the text field and click the button. You will see the label update with the text from the text field.</p>
<p>When I originally tried to build this application, I had to get Marcus&#8217; help. Then he showed me a great way to have the label update in real time as you type text into the text field. It was accomplished using the new <strong>@synthesize</strong> method in Objective-C 2.0. I won&#8217;t go into the details of that now, but needless to say there are a lot of different ways to achieve what you want for your app.</p>
<h1>Further Discussion</h1>
<p>It has been most helpful for me while learning to write code for the Mac that from an interface standpoint, there are two entities that you need to be concerned with&#8211;<em>actions</em> and <em>outlets</em>. <em>Outlets</em> are normally UI controls such as text fields, list boxes, and buttons while <em>actions</em> are, well, actions&#8211;the action you want to happen when some event from a control is triggered.</p>
<p>If you connect all of your <em>outlets</em> to their declarations in your controller/delegate code implementation, you don&#8217;t have to do any control object instantiation in code. There may be times when this is desirable, however, most of the time you can just connect and go. Just use your controls as all of the instantiation/initialization is handled for you by the framework.</p>
<p>&#8212;<br />
You can download the xCode project here: <a href='http://www.matthew-long.com/wp-content/uploads/2007/12/firstapp.zip' title='FirstApp Demo Application'>FirstApp Demo Application</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3030718858857706";
/* 468x15, created 2/7/08 */
google_ad_slot = "7586423078";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script><br />
<script type="text/javascript">
_uacct = "UA-80398-2";
urchinTracker();
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthew-long.com/2007/11/09/xcode-30-tutorial/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>
