<?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/"
	>

<channel>
	<title>I Love Code</title>
	<atom:link href="http://iloveco.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://iloveco.de</link>
	<description>Free Coding Tutorials and Resources</description>
	<pubDate>Wed, 02 Sep 2009 03:12:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>I Love Code now featuring User Content!</title>
		<link>http://iloveco.de/user-content/</link>
		<comments>http://iloveco.de/user-content/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 17:03:44 +0000</pubDate>
		<dc:creator>Alex Nichols</dc:creator>
		
		<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=632</guid>
		<description><![CDATA[As you may have noticed, the number of articles on I Love Code has been lower than usual over the past month. This is because the format that we originally were going to run the site in has not been working as well as we hoped. We originally planned to have all of the articles [...]


Related posts:<ol><li><a href='http://iloveco.de/donations/' rel='bookmark' title='Permanent Link: Donations'>Donations</a> <small>I Love Code is supported solely on donations. Not only...</small></li><li><a href='http://iloveco.de/temporary-slow-down/' rel='bookmark' title='Permanent Link: Temporary slow-down'>Temporary slow-down</a> <small>Hello! As you may have noticed, the number of tutorials...</small></li><li><a href='http://iloveco.de/hello-world/' rel='bookmark' title='Permanent Link: Hello world!'>Hello world!</a> <small>Welcome to I Love Code. I Love Code is a...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>As you may have noticed, the number of articles on I Love Code has been lower than usual over the past month. This is because the format that we originally were going to run the site in has not been working as well as we hoped. We originally planned to have all of the articles written by staff, and supported by donations as well as our premium service (which is coming soon), but we have received an extremely low number of donations since we launched, and our premium service is not ready yet. Because of this, we are not able to pay our wonderful staff to keep them working on I Love Code!</p>
<p>After talking to a few staff members, I think we have come up with a very good solution to this problem. We will now be accepting user submissions to I Love Code! Readers of the site can now submit tutorials that they have written on HTML, CSS, PHP, Javascript, and cocoa! To reward users for posting great tutorials, we will be giving away 3 prizes at the end of each month! One prize will be for the best tutorial (chosen by the staff), another prize will be for the most popular tutorial, and the final prize will go to the user that published the most tutorials in a month. The prizes will be announced at the beginning of each month! </p>
<p>Thank you,</p>
<p>-The I Love Code team</p>
<p>To submit an article, click the handy &#8220;Submit an Article&#8221; link at the top of the page, or click <a href="http://iloveco.de/submit">here</a>.</p>


<p>Related posts:<ol><li><a href='http://iloveco.de/donations/' rel='bookmark' title='Permanent Link: Donations'>Donations</a> <small>I Love Code is supported solely on donations. Not only...</small></li><li><a href='http://iloveco.de/temporary-slow-down/' rel='bookmark' title='Permanent Link: Temporary slow-down'>Temporary slow-down</a> <small>Hello! As you may have noticed, the number of tutorials...</small></li><li><a href='http://iloveco.de/hello-world/' rel='bookmark' title='Permanent Link: Hello world!'>Hello world!</a> <small>Welcome to I Love Code. I Love Code is a...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/user-content/feed/</wfw:commentRss>
		</item>
		<item>
		<title>UIKit Alert Types</title>
		<link>http://iloveco.de/uikit-alert-types/</link>
		<comments>http://iloveco.de/uikit-alert-types/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 17:35:37 +0000</pubDate>
		<dc:creator>Tim Davies</dc:creator>
		
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=620</guid>
		<description><![CDATA[
There are many kinds of alert views that you can utilise within Apple&#8217;s UIKit, the most obvious being UIAlertView. However there are also UIActionSheets and the undocumented UIProgressHUD, the pretty Volume like HUD that you see on mac that apple use within their own iPhone applications. It&#8217;s there for you to use, however do be [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><img src="http://iloveco.de/images/easy.png" alt="" /></p>
<p>There are many kinds of alert views that you can utilise within Apple&#8217;s <em>UIKit</em>, the most obvious being <em>UIAlertView</em>. However there are also <em>UIActionSheets </em>and the undocumented <em>UIProgressHUD</em>, the pretty Volume like HUD that you see on mac that apple use within their own iPhone applications. It&#8217;s there for you to use, however do be warned if not used correctly apple WILL not let your app onto the AppStore as this is a <em>Private </em>API.</p>
<p><strong>UIAlertView, iPhones typical alert view.<br />
<span style="font-weight: normal;">UIAlertView is used throughout the iPhone OS for things such as text messages (SMS) and <em>Push Notifications</em>.</span></strong></p>
<p>Implementing <em>UIAlertView </em>is extremely simple and handling button taps is done through a delegate method. For more information on handling button taps with the <em>UIAlertView </em>delegate method please refer to the demonstration project attached to this article.</p>
<p>Firstly we allocate and initialise a <em>UIAlertView </em>object.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">UIAlertView *myAlert = <span class="br0">&#91;</span><span class="br0">&#91;</span>UIAlertView alloc<span class="br0">&#93;</span> initWithTitle:@<span class="st0">&quot;ILOVECO.DE&quot;</span><br />
message:@<span class="st0">&quot;This is a UIAlertView, subclass of UIView.&quot;</span><br />
delegate:self<br />
cancelButtonTitle:@<span class="st0">&quot;Cancel&quot;</span><br />
otherButtonTitles:@<span class="st0">&quot;Do Somthing&quot;</span>, <span class="kw2">nil</span><span class="br0">&#93;</span>;</div>
</div>
<p><strong> </strong></p>
<p>The method used for initialisation in most cases is - <em>(id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, &#8230; </em>This method will create the <em>UIAlertView </em>with the given parameters and allocate the object memory until it&#8217;s released.</p>
<p>To display the <em>UIAlertView </em>we simply call the <em>show</em> method, once this method has been called you can go ahead and release the <em>UIAlertView </em>object.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>myAlert show<span class="br0">&#93;</span>;<br />
<span class="br0">&#91;</span>myAlert release<span class="br0">&#93;</span>;</div>
</div>
<p>This <em>UIAlertView </em>object will display the <em>UIAlertView </em>buttons in a typical fashion, one beside the other.</p>
<div><img class="alignnone" title="UIAlertView" src="http://dznr.org/to2j" alt="" width="295" height="169" /></p>
<p>However there is a private method, <em>setNumberOfRows:(int)n </em>that will allow you to set a maximum number of rows to display the buttons in. To use this method we need to add our own additions to the <em>UIAlertView </em>class. We do this by adding an <em>@interface </em>for <em>UIAlertView </em>in our <strong>.m</strong> file.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">// extend the UIAlertView class to remove the warning caused</span><br />
<span class="co1">// by calling setNumberOfRows.</span></p>
<p><span class="kw4">@interface</span> UIAlertView <span class="br0">&#40;</span>extended<span class="br0">&#41;</span></p>
<p>- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span> setNumberOfRows:<span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span>num;</p>
<p><span class="kw4">@end</span></div>
</div>
<p>This will allow us to call the method without the compiler throwing us a warning.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>myAlert setNumberOfRows:<span class="nu0">2</span><span class="br0">&#93;</span>;</div>
</div>
<p>This method call will result in the <em>UIAlertView </em>displaying the buttons on separate rows, the following image depicts the result.</p>
<p><img src="http://dznr.org/zonn" alt="UIAlertViewRows" /></p>
<p>Just like any UIView subclass this object will also respond to you adding subviews, this will allow you to implement <em>UIProgressView&#8217;s</em> and other objects such as switches</p>
<p><strong>UIActionSheet, you know, the one that slides up…<br />
<span style="font-weight: normal; "><em>UIActionSheet </em>objects are also used throughout the iPhone OS. Apple applications use these to present the user with contextual options, much like a contextual menu on a desktop platform. An example within of a <em>UIActionSheet </em>within an Apple application would be <em>Mail.app </em>When you select the actions button when reading an email you are presented with a <em>UIActionSheet.</em></span></strong></p>
<p>Similar to the <em>UIAlertView</em> the action sheet view is allocated and then initialised with parameters such as a title string and an array of buttons. Remember that the list of other button titles must always end with a nil parameter.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">UIActionSheet *sheet = <span class="br0">&#91;</span><span class="br0">&#91;</span>UIActionSheet alloc<span class="br0">&#93;</span> initWithTitle:@<span class="st0">&quot;Pick an action, any action!&quot;</span><br />
delegate:self<br />
cancelButtonTitle:@<span class="st0">&quot;Dismiss&quot;</span><br />
destructiveButtonTitle:@<span class="st0">&quot;Delete SMS&quot;</span><br />
otherButtonTitles:@<span class="st0">&quot;Forward SMS&quot;</span>, @<span class="st0">&quot;Copy SMS&quot;</span>, <span class="kw2">nil</span><span class="br0">&#93;</span>;</div>
</div>
<p>Again this method will allocate and initialise a <em>UIActionSheet </em>object. Displaying the action sheet requires the <em>showIinView </em>method and it requires a single parameter, the <em>UIView (or subclass) </em>you wish to display the action sheet in. Most of the time, and in this example I will be using the applications key window (<em>[[UIApplication sharedApplication] keyWindow])</em>.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>sheet showInView:<span class="br0">&#91;</span><span class="br0">&#91;</span>UIApplication sharedApplication<span class="br0">&#93;</span> keyWindow<span class="br0">&#93;</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#91;</span>sheet release<span class="br0">&#93;</span>;</div>
</div>
<p>As soon as you have displayed the view you can release it.</p>
<p><img src="http://dznr.org/uw0o" alt="ActionSheet" /></p>
<p><strong>UIProgressHUD, the one they hid from you!<br />
<span style="font-weight: normal;">The <em>UIProgressHUD </em>is an alert that isn&#8217;t discussed within the API documentation, to use <em>UIProgressHUD</em> we need to create an <em>@interface </em>for it. This ones long. The comment in the code below explains why.</span></strong></p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">// Create the UIProgressHUD class</span><br />
<span class="co1">// THIS IS A COPY FROM UIProgressHUD.h from UIKit&#8217;s private</span><br />
<span class="co1">// frameworks and should be used with the under standing</span><br />
<span class="co1">// that Apple may wish to deny your app to the App Store</span></p>
<p><span class="kw4">@interface</span> UIProgressHUD : UIView<br />
<span class="br0">&#123;</span><br />
UIProgressView *_progressIndicator;<br />
UILabel *_progressMessage;<br />
UIImageView *_doneView;<br />
UIWindow *_parentWindow;<br />
<span class="kw4">struct</span> <span class="br0">&#123;</span><br />
<span class="kw4">unsigned</span> <span class="kw4">int</span> isShowing:<span class="nu0">1</span>;<br />
<span class="kw4">unsigned</span> <span class="kw4">int</span> isShowingText:<span class="nu0">1</span>;<br />
<span class="kw4">unsigned</span> <span class="kw4">int</span> fixedFrame:<span class="nu0">1</span>;<br />
<span class="kw4">unsigned</span> <span class="kw4">int</span> reserved:<span class="nu0">30</span>;<br />
<span class="br0">&#125;</span> _progressHUDFlags;<br />
<span class="br0">&#125;</span></p>
<p>- <span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span>_progressIndicator;<br />
- <span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span> initWithWindow:<span class="br0">&#40;</span>UIWindow *<span class="br0">&#41;</span>window;<br />
- <span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span>initWithFrame:<span class="br0">&#40;</span><span class="kw4">struct</span> CGRect<span class="br0">&#41;</span>fp8;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>setText:<span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span>fp8;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>setShowsText:<span class="br0">&#40;</span><span class="kw4">BOOL</span><span class="br0">&#41;</span>fp8;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>setFontSize:<span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span>fp8;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>drawRect:<span class="br0">&#40;</span><span class="kw4">struct</span> CGRect<span class="br0">&#41;</span>fp8;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>layoutSubviews;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>showInView:<span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span>fp8;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>hide;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>done;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>dealloc;<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span> show:<span class="br0">&#40;</span><span class="kw4">BOOL</span><span class="br0">&#41;</span>aShow;</p>
<p><span class="kw4">@end</span></div>
</div>
<p>Being a private API UIKit will parse any calls we make or objects we initialise however the compiler will not build our application without an <em>@interface </em>for the <em>UIProgressHUD </em>object so here I simply copied the <em>UIProgressHUD.h </em>from the <em>UIKit Private Headers</em>.</p>
<p>Creating a <em>UIProgressHUD</em> is now as simple as creating and other UI object and control.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">// create the HUD using the methods we defined for it in the @interface above</span><br />
UIProgressHUD *HUD = <span class="br0">&#91;</span><span class="br0">&#91;</span>UIProgressHUD alloc<span class="br0">&#93;</span> initWithWindow:<span class="br0">&#91;</span><span class="br0">&#91;</span>UIApplication sharedApplication<span class="br0">&#93;</span> keyWindow<span class="br0">&#93;</span><span class="br0">&#93;</span>;</div>
</div>
<p>This object is now allocated, initialised and ready to display. We can set some text for the view, and then display it with the following.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>HUD setText:@<span class="st0">&quot;Doing Something…&quot;</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#91;</span>HUD show:YES<span class="br0">&#93;</span>;</div>
</div>
<p>This will display the alert onscreen see the output below.</p>
<p><img src="http://dznr.org/5m7l" alt="ProgressHUD" /></p>
<p>This alert can then be told the intermediate action had completed and display a tick in place of a progress indicator, the methods to do this and then remove the alert from superView are show in the interface declaration but for the sake of this tutorial I shall post some code below using timed method calls to change the alert&#8217;s state. This code comes directly from the example project so do check it out!</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">// simulate the different statuses using a timer, normaly you would set these</span><br />
<span class="co1">// in different methods.</span><br />
<span class="br0">&#91;</span>HUD performSelector:<span class="kw4">@selector</span><span class="br0">&#40;</span>done<span class="br0">&#41;</span> withObject:<span class="kw2">nil</span> afterDelay:<span class="nu0">1.2</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#91;</span>HUD performSelector:<span class="kw4">@selector</span><span class="br0">&#40;</span>setText:<span class="br0">&#41;</span> withObject:@<span class="st0">&quot;Done Somthing!&quot;</span> afterDelay:<span class="nu0">1.2</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#91;</span>HUD performSelector:<span class="kw4">@selector</span><span class="br0">&#40;</span>hide<span class="br0">&#41;</span> withObject:<span class="kw2">nil</span> afterDelay:<span class="nu0">2.0</span><span class="br0">&#93;</span>;</p>
<p><span class="co1">//release the object, save on memory!</span><br />
<span class="br0">&#91;</span>HUD release<span class="br0">&#93;</span>;</div>
</div>
<p>This concludes my article on types of alerts found within iPhones UIKit framework. For information on delegate methods for handling button clicks within the <em>UIAlertView </em>and <em>UIActionSheet</em> please refer to the sample project where its all quite clear and commented. For further information search the class names in the Cocoa Touch documentation either online at developer.apple.com or from within xcode.</p>
<p>The source code contains a copy of the tutorial for use offline as well as the xcode project for you to read through<br />
<a href="http://dznr.org/ey0s"><img src="http://iloveco.de/images/source.png" alt="" /></a><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=5158477"><img src="http://iloveco.de/images/donate2.png" alt="" /></a></div>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/uikit-alert-types/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Speech Synthesis on iPhone 3GS</title>
		<link>http://iloveco.de/speech-synthesis-on-iphone-3gs/</link>
		<comments>http://iloveco.de/speech-synthesis-on-iphone-3gs/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 05:37:40 +0000</pubDate>
		<dc:creator>Steven Troughton-Smith</dc:creator>
		
		<category><![CDATA[iPhone]]></category>

		<category><![CDATA[3gs]]></category>

		<category><![CDATA[cocoa]]></category>

		<category><![CDATA[private api]]></category>

		<category><![CDATA[speech]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=609</guid>
		<description><![CDATA[The simple way to do Voice Synthesis (or 'Speech') on the iPhone 3GS; three lines of code.


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how to do simple voice synthesis on the iPhone 3GS (3GS-only, I&#8217;m afraid). It&#8217;s a private API, but hopefully if we file enough <a href="http://radar.apple.com">Radars</a> they&#8217;ll make it a public one!</p>
<p>To enable the following code to work you&#8217;ll need to link the VoiceServices.framework (from the PrivateFrameworks folder of the SDK) in your app.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSObject.html"><span class="kw5">NSObject</span></a> *v = <span class="br0">&#91;</span><span class="br0">&#91;</span>NSClassFromString<span class="br0">&#40;</span>@<span class="st0">&quot;VSSpeechSynthesizer&quot;</span><span class="br0">&#41;</span> alloc<span class="br0">&#93;</span> init<span class="br0">&#93;</span>;<br />
<span class="br0">&#91;</span>v startSpeakingString:@<span class="st0">&quot;All your base are belong to us&quot;</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#91;</span>v release<span class="br0">&#93;</span>;</div>
</div>
<p>Apologies for my lazy &#8216;NSObject&#8217; define above, but you get the idea <img src='http://iloveco.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>With that, you have simple speech synthesis for your application (obviously you cannot include this when you submit to the App Store as it links to a private framework, but you can use it in your internal applications). It requires the 3GS because the Speech stuff just isn&#8217;t in the firmware for the older devices.</p>
<p>Obligatory video below:</p>
<p><center><embed src="http://img40.imageshack.us/flvplayer.swf?f=Pym1" width="420" height="298" allowFullScreen="true" type="application/x-shockwave-flash"></embed></center></p>
<p>Reblogged from <a href="http://blog.steventroughtonsmith.com/2009/07/speech-synthesis-on-iphone-3gs.html">my blog</a>.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/speech-synthesis-on-iphone-3gs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adding a Handle Bar Separator to Your Application</title>
		<link>http://iloveco.de/seperator/</link>
		<comments>http://iloveco.de/seperator/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 00:41:28 +0000</pubDate>
		<dc:creator>Alex Zielenski</dc:creator>
		
		<category><![CDATA[Mac]]></category>

		<category><![CDATA[bar]]></category>

		<category><![CDATA[bottom]]></category>

		<category><![CDATA[c]]></category>

		<category><![CDATA[cocoa]]></category>

		<category><![CDATA[fontcase]]></category>

		<category><![CDATA[handle]]></category>

		<category><![CDATA[ns]]></category>

		<category><![CDATA[nssplitview]]></category>

		<category><![CDATA[objc]]></category>

		<category><![CDATA[objective]]></category>

		<category><![CDATA[objective-c]]></category>

		<category><![CDATA[os]]></category>

		<category><![CDATA[osx]]></category>

		<category><![CDATA[resize]]></category>

		<category><![CDATA[split]]></category>

		<category><![CDATA[splitview]]></category>

		<category><![CDATA[view]]></category>

		<category><![CDATA[x]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=591</guid>
		<description><![CDATA[This tutorial will teach you how to make the small handle that goes on a bottom bar of some apps to resize a SplitView.


Related posts:<ol><li><a href='http://iloveco.de/adding-a-titlebar-accessory-view-to-a-window/' rel='bookmark' title='Permanent Link: Adding a Titlebar Accessory View to a Window'>Adding a Titlebar Accessory View to a Window</a> <small> We&#8217;ve all seen it done before: some applications make...</small></li><li><a href='http://iloveco.de/relaunching-your-application/' rel='bookmark' title='Permanent Link: Relaunching your application'>Relaunching your application</a> <small> Whether you&#8217;re applying new preferences, installing a new version...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.iloveco.de/images/medium.png"><br />
This tutorial will teach you how to make the small handle that goes on a bottom bar of some apps such as Fontcase, as you can see here:</p>
<p><img src="http://iloveco.de/hb/1.png" alt="Fontcase" /></p>
<p>In this tutorial, you will learn how to make this bit:</p>
<p><img src="http://iloveco.de/hb/7.png" alt="Bottom Bar Handle" /></p>
<p>Ok, so, there is a couple problems we will run into during this tutorial. Problems like not being able to move the window with the bottom bar since the split view will be intercepting the mouse events and making the separator move with the split view. This tutorial assumes only that you know your way around XCode/Interface Builder, and know to subclass things. So let’s get started.</p>
<h1><span style="font-weight: bold;">Part 1</span></h1>
<p>First, we need to make our project, so go ahead and make a Cocoa Application (File-&gt;New Project in XCode)</p>
<p><img src="http://www.iloveco.de/hb/2.png" alt="" /></p>
<p>The first thing you need to do is design an interface. So, just expand the resources folder in XCode, and open up MainMenu.xib.</p>
<p><img src="http://www.iloveco.de/hb/8.png" alt="" /></p>
<p>Next, we need to do is make our split view. Drag a vertical NSSplitView from the Library, onto the window.</p>
<p><img src="http://www.iloveco.de/hb/9.png" alt="" /></p>
<p>Customize the settings in inspector until you get a desired result. Here is mine:</p>
<p><img src="http://www.iloveco.de/hb/11.png" alt="" /></p>
<p>Make sure your split view resizes with the window in the size panel of inspector:</p>
<p><img src="http://www.iloveco.de/hb/4.png" alt="" /></p>
<p>I’ve just added some elements to my window to make it look more like an application (Make sure to import the appropriate frameworks if you do this).</p>
<p><img src="http://www.iloveco.de/hb/10.png" alt="" /></p>
<p>The reason I’ve left space at the bottom is to make room for the bottom bar. Which we will add soon. You now need to add your resize handle image into the project resources folder, here is one for you:</p>
<p><img src="http://www.iloveco.de/hb/POVerticalSplit.png" alt="" /></p>
<p>When you have it in your project, you need to drag it in from the media tab in the library. Just vertically center it with the space you left for the bottom bar. Make sure to put it inside the the subview you want it to resize. Go to the size panel and set these settings for you handle image so it moves with the view.</p>
<p><img src="http://www.iloveco.de/hb/5.png" alt="" /></p>
<p>What you need to do now is make a Controller class. And set it as the delegate of the split view. You also need to make outlets to the window, and the handle image.</p>
<p><img src="http://www.iloveco.de/hb/3.png" alt="" /></p>
<p>Write the class files for this class. (File-&gt;Write Class Files) Make sure to specify a superclass (NSObject) in the header file. In the .m file, you need to add a new method, it will be “awakeFromNib” We will use this to create a bottom bar on the window.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw4">@implementation</span> AppController<br />
- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>awakeFromNib <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>window setContentBorderThickness:<span class="nu0">34.0</span> forEdge:NSMinYEdge<span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw4">@end</span></div>
</div>
<p>
So now you have your bottom bar. But we have a problem here. The first is that the line that goes on the bottom bar isn’t dark enough, and the second is that the bottom bar won’t move the window when you try to drag it. Both of these fixed when we subclass the NSSplitView. But for now, we will set the handle as the divider. To do this, we need to use our delegate and a delegate method. So, make sure you have your controller set as the split view’s delegate. After the awakeFromNib method, add this one:<br />
</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">- <span class="br0">&#40;</span><span class="kw4">NSRect</span><span class="br0">&#41;</span>splitView:<span class="br0">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSSplitView.html"><span class="kw6">NSSplitView</span></a> *<span class="br0">&#41;</span>splitView additionalEffectiveRectOfDividerAtIndex:<span class="br0">&#40;</span>NSInteger<span class="br0">&#41;</span>dividerIndex <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#91;</span>handle convertRect: <span class="br0">&#91;</span>handle bounds<span class="br0">&#93;</span> toView:splitView<span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>
If you had a different handle outlet name, you will need to change that, but this line is self explanatory, it says, “Add another divider around the bounds (edges) of our handle.”<br />
So if you were to build and go right now, you can resize the split view with the handle. It is now time to subclass the NSSplitView to get the bottom bar to be able to move the window, and change the divider line color.<br />
</br>
</p>
<p><h1>Part 2</h1>
<p>
This tutorial assumes you know how to subclass objects, so go ahead and write the class files for your NSSplitView subclass. Don’t forget to specify a superclass.</p>
<p>To get the bottom border working, you need to have it so the SplitView can move the window because the splitview is overlapping the bottom bar, thus; intercepting it’s mouse events. So to make the split view able to move the window, add this method to your subclass’ “.m” file.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">- <span class="br0">&#40;</span><span class="kw4">BOOL</span><span class="br0">&#41;</span>mouseDownCanMoveWindow <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> YES;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></div>
</div>
<p>
That’s it! So now to edit the line color that was bothering us, and to fix that, we use our subclass to return a dividerColor. Add this after your “mouseDownCanMoveWindow” method.<br />
</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">- <span class="br0">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSColor.html"><span class="kw6">NSColor</span></a> *<span class="br0">&#41;</span>dividerColor <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSColor.html"><span class="kw6">NSColor</span></a> darkGrayColor<span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>
If you followed my instructions perfectly or similarly, you should have something close to this:<br />
<br />
<img src="http://www.iloveco.de/hb/10.png"><br />
<br />
I hope you enjoyed this tutorial and find all information you learned in here useful and execute it wisely.</p>
<p><a href="http://iloveco.de/hb/source.zip"><img src="http://iloveco.de/images/source.png" alt="" /></a><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=5158477"><img src="http://iloveco.de/images/donate2.png" alt="" /></a></p>


<p>Related posts:<ol><li><a href='http://iloveco.de/adding-a-titlebar-accessory-view-to-a-window/' rel='bookmark' title='Permanent Link: Adding a Titlebar Accessory View to a Window'>Adding a Titlebar Accessory View to a Window</a> <small> We&#8217;ve all seen it done before: some applications make...</small></li><li><a href='http://iloveco.de/relaunching-your-application/' rel='bookmark' title='Permanent Link: Relaunching your application'>Relaunching your application</a> <small> Whether you&#8217;re applying new preferences, installing a new version...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/seperator/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Programming a Menu Bar Button</title>
		<link>http://iloveco.de/menu-bar-button/</link>
		<comments>http://iloveco.de/menu-bar-button/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 05:03:15 +0000</pubDate>
		<dc:creator>Carter Allen</dc:creator>
		
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=579</guid>
		<description><![CDATA[
The goal of this tutorial is to teach you how to create an icon in the menu bar for your application, which when pressed, activates the main application window. An example of this can be seen in the Iconfactory&#8217;s Twitterrific. The main class you will be exploring in this tutorial is NSStatusItem. Apple&#8217;s documentation for [...]


Related posts:<ol><li><a href='http://iloveco.de/object-oriented-programming/' rel='bookmark' title='Permanent Link: Understanding Object-Oriented Programming and the MVC System'>Understanding Object-Oriented Programming and the MVC System</a> <small> Introduction Before you begin to learn the basic syntax...</small></li><li><a href='http://iloveco.de/basic-c-programming-2/' rel='bookmark' title='Permanent Link: Basic C Programming'>Basic C Programming</a> <small>In This tutorial, we will look at the basic principles...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://iloveco.de/images/medium.png" alt="" /><br />
The goal of this tutorial is to teach you how to create an icon in the menu bar for your application, which when pressed, activates the main application window. An example of this can be seen in the <a title="Twitterrific by the Iconfactory" href="http://twitterrific.com/" target="_blank">Iconfactory&#8217;s Twitterrific</a>. The main class you will be exploring in this tutorial is NSStatusItem. Apple&#8217;s documentation for the NSStatusItem class can be found <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSStatusItem_Class/Reference/Reference.html" target="_blank">here</a>.</p>
<p><strong>Before we go on, I&#8217;d like to note that this simple usage of a menubar icon severely violates the Apple Human Interface Guidelines. The menubar of the system should not ever be used like the system tray is in Windows. A menubar icon should perform more actions than simply showing/hiding an app&#8217;s window, and cluttering up the menubar with an icon for every application makes no sense whatsoever. Notice the dock at the bottom of your screen:  that&#8217;s why it is there.</strong></p>
<p><strong>Step 1.</strong> Open XCode.app and create a new project. For now, let&#8217;s stick with simplicity and choose &#8220;Cocoa Application.&#8221; Name the project &#8220;AwesomeMenubarButton,&#8221; and go on to the next step.</p>
<p><strong>Step 2.</strong> We&#8217;re going to need to set up the project with a controller. Create a new Objective-C class and call it &#8220;AppController.&#8221;</p>
<p><strong>Step 3.</strong> Next we&#8217;ll need to add outlets for all of the needed UI components. In the case of this project, we&#8217;re only going to need on outlet:  the main window that we&#8217;re going to be hiding and showing. Add the following code in the @interface section of AppController.h:</p>
<p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">IBOutlet <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSWindow.html"><span class="kw6">NSWindow</span></a> *mainWindow;</div>
</div>
<p><strong>Step 4.</strong> There are two different actions that the menubar button will be performing:  showing the window, and hiding it. For simplicity, we can simplify these two actions into one method that &#8220;toggles&#8221; the visibility of the window. Directly under the @interface section in AppController.h, add the following code:</p>
<p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>toggleVisibilityOfMainWindow:<span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span>sender;</div>
</div>
<p>And let&#8217;s add the window toggling code in AppController.m:</p>
<p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">- <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>toggleVisibilityOfMainWindow:<span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span>sender <span class="br0">&#123;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#91;</span>mainWindow isVisible<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="br0">&#91;</span>mainWindow orderOut:<span class="kw2">nil</span><span class="br0">&#93;</span>;<br />
<span class="kw1">return</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#91;</span>mainWindow makeKeyAndOrderFront:<span class="kw2">nil</span><span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Save both files and lets move on.</p>
<p><strong>Step 5.</strong> Open MainMenu.xib in Interface Builder and select File: Read Class Files. Browse to the AppController.h file that we created, and open it. Add a new blank NSObject from the library into your document, and go into the Identity tab of the inspector. Set the object&#8217;s Class to &#8220;AppController.&#8221; The name of the object should now change in the document window.</p>
<p><strong>Step 6.</strong> Make sure you still have the App Controller object selected, and go into the Connections inspector. Drag a connection from the mainWindow outlet to the only window in the xib file. Save and close!</p>
<p><strong>Step 7.</strong> Here is where it starts to get tricky. NSStatusItem, the class that we&#8217;re going to use to make the menubar icon/button cannot be added in Interface Builder:  we have to create it via code. Go back to AppController.m and add the following method implementation:</p>
<p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSStatusItem.html"><span class="kw6">NSStatusItem</span></a> *statusItem = <span class="br0">&#91;</span><span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSStatusBar.html"><span class="kw6">NSStatusBar</span></a> systemStatusBar<span class="br0">&#93;</span> statusItemWithLength:NSSquareStatusItemLength<span class="br0">&#93;</span> retain<span class="br0">&#93;</span>;&lt;br /&gt;<br />
<span class="br0">&#91;</span>statusItem setTitle:@<span class="st0">&quot;A&quot;</span><span class="br0">&#93;</span>;&lt;br /&gt;<br />
<span class="co1">// Uncomment this area and fill in the name of your image&lt;br /&gt;</span><br />
<span class="co1">// to add a custom icon to your status item.&lt;br /&gt;</span><br />
<span class="co1">//[statusItem setImage:[NSImage imageNamed:@&quot;Icon&quot;]];&lt;br /&gt;</span><br />
<span class="br0">&#91;</span>statusItem setEnabled:YES<span class="br0">&#93;</span>;&lt;br /&gt;<br />
<span class="br0">&#91;</span>statusItem setHighlightMode:YES<span class="br0">&#93;</span>;&lt;br /&gt;<br />
<span class="br0">&#91;</span>statusItem setTarget:self<span class="br0">&#93;</span>; <span class="co1">//This sets the AppController as the receiver of all sent actions.&lt;br /&gt;</span><br />
<span class="br0">&#91;</span>statusItem setAction:<span class="kw4">@selector</span><span class="br0">&#40;</span>toggleVisibilityOfMainWindow:<span class="br0">&#41;</span><span class="br0">&#93;</span>; <span class="co1">//This tells the status item to call our toggle method when clicked.</span></div>
</div>
<p>You&#8217;re all done! Build and Go, and the menu item will appear and when pressed, it will toggle the visibility of the main window.</p>
<p><a href="http://www.dl.opt-6.com/public/ambb.zip"><img src="http://iloveco.de/images/source.png" alt="" /></a><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=5158477"><img src="http://iloveco.de/images/donate2.png" alt="" /></a></p>


<p>Related posts:<ol><li><a href='http://iloveco.de/object-oriented-programming/' rel='bookmark' title='Permanent Link: Understanding Object-Oriented Programming and the MVC System'>Understanding Object-Oriented Programming and the MVC System</a> <small> Introduction Before you begin to learn the basic syntax...</small></li><li><a href='http://iloveco.de/basic-c-programming-2/' rel='bookmark' title='Permanent Link: Basic C Programming'>Basic C Programming</a> <small>In This tutorial, we will look at the basic principles...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/menu-bar-button/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Effectively using NSBox</title>
		<link>http://iloveco.de/effectively-using-nsbox/</link>
		<comments>http://iloveco.de/effectively-using-nsbox/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 02:37:44 +0000</pubDate>
		<dc:creator>Steven Degutis</dc:creator>
		
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=574</guid>
		<description><![CDATA[
Whenever we Cocoa devs think of NSBox, we usually think of a nice, basic container for other views, that comes with a title, right? Something that looks like this, maybe:

Well, this is only the beginning of NSBox&#8217;s flexibility. When we set Box Type to Custom, this opens up 6 properties of NSBox that we can [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><center><img src="http://iloveco.de/images/easy.png"></center></p>
<p>Whenever we Cocoa devs think of NSBox, we usually think of a nice, basic container for other views, that comes with a title, right? Something that looks like this, maybe:</p>
<p><img src="/images/boxblog_box1.png"></p>
<p>Well, this is only the beginning of NSBox&#8217;s flexibility. When we set Box Type to Custom, this opens up 6 properties of NSBox that we can now make use of for our custom layouts: border and background colors, horizontal and vertical margins, and probably the most unexpected properties, the border width and radius.</p>
<p>This gives us a ton of flexibility to do all sorts of sexy basic layout shapes. Combined with the fact that you can very easily change out the content view of an NSBox (via -setContentView:), this little control becomes a very powerful UI element. And when applying a little imagination, we can make our interfaces look much nicer with much fewer custom NSView subclasses.</p>
<p>For instance, the setup window for Adium (very similar looking to Installer.app) could make use of NSBox (if it doesn&#8217;t already) for its main &#8220;content&#8221; view, which gives a basic and nice looking layout.</p>
<p><img src="/images/boxblog_box2.png" width=500></p>
<p>Normally this would be done with an NSView that draws the translucently-colored border and background itself, and when we want to swap views out, we would have to make sure to set their frame size appropriately, so that they appear where we expect them to. With NSBox, setting the content view does this resizing and repositioning for us for free, plus we don&#8217;t even need to touch any code to get the box to appear like it does in this Adium screenshot.</p>
<p>Here are just some of the things you can do with an NSBox in Interface Builder by itself, without even writing a line of code:</p>
<p><img src="/images/boxblog_box3.png"></p>
<p>I&#8217;m not claiming those sample boxes in that last screenshot look good or should even be used in an app, but there&#8217;s plenty of ways you could use this flexibility to get rid of some custom NSView subclasses.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/effectively-using-nsbox/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Integrating WebView into a Cocoa app</title>
		<link>http://iloveco.de/integrating-webview-into-a-cocoa-app/</link>
		<comments>http://iloveco.de/integrating-webview-into-a-cocoa-app/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 17:53:55 +0000</pubDate>
		<dc:creator>Steven Degutis</dc:creator>
		
		<category><![CDATA[Announcements]]></category>

		<category><![CDATA[HTML/CSS]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Mac]]></category>

		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=563</guid>
		<description><![CDATA[
When using a WebView object inside a Cocoa application, one might think they are limited to only displaying web pages. However, using custom CSS and JavaScript, a WebView object can become a very powerful and flexible part of a Cocoa app, while looking and working natively.
The first thing you should know is that there is [...]


Related posts:<ol><li><a href='http://iloveco.de/adding-isight/' rel='bookmark' title='Permanent Link: Integrating iSight into your cocoa application…'>Integrating iSight into your cocoa application…</a> <small>Having iSight integrated into you app can be useful in...</small></li><li><a href='http://iloveco.de/bottom-bars-in-cocoa/' rel='bookmark' title='Permanent Link: Bottom Bars in Cocoa'>Bottom Bars in Cocoa</a> <small> Mac OS X 10.5 Leopard introduced a new user...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://iloveco.de/images/medium.png"></p>
<p>When using a WebView object inside a Cocoa application, one might think they are limited to only displaying web pages. However, using custom CSS and JavaScript, a WebView object can become a very powerful and flexible part of a Cocoa app, while looking and working natively.</p>
<p>The first thing you should know is that there is <a href="http://developer.apple.com/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html">plenty of WebKit-specific CSS</a>. Because you&#8217;re writing for a WebView object only, you can (thankfully) ignore all other browsers, and thus you get to use all of this WebKit goodness without any worry. For example, your &#8216;background-color&#8217; can now be set to &#8216;window&#8217; which is a handy constant telling the browser to render the color the same as the background of a Cocoa window. There&#8217;s also -webkit-appearance, which, while a little lacking at the moment, is a great way to make your element look like native Cocoa search fields, buttons, and text fields, among other controls. Another great feature of WebKit is the &#8220;webkit-gradient&#8221; function, which essentially allows developers and designers to replace custom gradient graphics with brief, flexible, and most importantly, editable, CSS code.</p>
<p>Now that we can utilize WebKit&#8217;s specific CSS to get a nice native-looking user interface, we need to make it do something! Enter WebScriptObject. This is a class brought in by WebKit.framework, and is used in Cocoa. Normally the only WebScriptObject that Cocoa developers should touch is the one received by calling -[WebView windowScriptObject]. This gives you a handle on your WebView&#8217;s scripting object, and once you call this, you can do two very important things:</p>
<p>First of all, you can call JavaScript functions from inside your Cocoa app. You do this by calling -evaluateWebScript or -callWebScriptMethod:withArguments: on your WebView&#8217;s -windowScriptObject. This will return a value if your JS function does so, or at the very least, executes a JS function inside your WebView. This is handy for, say, refreshing information inside your WebView.</p>
<p>Secondly, and probably more importantly, you can set new objects that your JavaScript scripts inside your WebView can call functions (methods) on. We do this with basic KVC. For example, calling [scriptObject setValue:self forKey:@"ControllerObject"] will give the JavaScript environment a new top-level object called ControllerObject. Now, you can call Cocoa methods from inside JavaScript. There&#8217;s only two gotcha, but they can be a little elusive at first:</p>
<p>The first gotcha is naming conventions. If your Cocoa object implements -method, then method() is the function you can call on it. Pretty simple, right? But what if your method is -method:withObject:? Like in the other scripting bridges, simply replace colons with underscores. This, that method becomes method_withObject_(). Kind of lame, I agree, but if it really bugs you can implement +webScriptNameForSelector: which is found in WebScripting informal protocol.</p>
<p>The second gotcha is related to that protocol I just brought up for the first time. See, any object that lives inside your JavaScript environment, implicitly conforms to WebScripting, except it usually doesn&#8217;t implement any of these optional methods. There&#8217;s two very important methods you&#8217;ll have to implement before your JS code can call any Cocoa:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">+ <span class="br0">&#40;</span><span class="kw4">BOOL</span><span class="br0">&#41;</span>isSelectorExcludedFromWebScript:<span class="br0">&#40;</span><span class="kw4">SEL</span><span class="br0">&#41;</span>aSelector<br />
+ <span class="br0">&#40;</span><span class="kw4">BOOL</span><span class="br0">&#41;</span>isKeyExcludedFromWebScript:<span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">char</span> *<span class="br0">&#41;</span>name</div>
</div>
<p>Implement these and return NO for both, while you&#8217;re testing. Otherwise, your Cocoa calls from inside JS will never be executed! I recommend that once you&#8217;re out of development phase, you make these methods conditional and only allow methods/keys that you call from inside your JS code, for security purposes.</p>
<p>Yes, it takes a little bit of work, but in the end, you have a WebView that looks beautiful and native, and actually interacts with the rest of your app!</p>


<p>Related posts:<ol><li><a href='http://iloveco.de/adding-isight/' rel='bookmark' title='Permanent Link: Integrating iSight into your cocoa application…'>Integrating iSight into your cocoa application…</a> <small>Having iSight integrated into you app can be useful in...</small></li><li><a href='http://iloveco.de/bottom-bars-in-cocoa/' rel='bookmark' title='Permanent Link: Bottom Bars in Cocoa'>Bottom Bars in Cocoa</a> <small> Mac OS X 10.5 Leopard introduced a new user...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/integrating-webview-into-a-cocoa-app/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Temporary slow-down</title>
		<link>http://iloveco.de/temporary-slow-down/</link>
		<comments>http://iloveco.de/temporary-slow-down/#comments</comments>
		<pubDate>Thu, 28 May 2009 22:58:50 +0000</pubDate>
		<dc:creator>Alex Nichols</dc:creator>
		
		<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=557</guid>
		<description><![CDATA[Hello!  As you may have noticed, the number of tutorials being published on the site has decreasing recently. This is because of the fact that a lot of our great staff members have been extremely busy recently with a lot of exciting projects! A lot of us, including yours truly, are currently very busy [...]


Related posts:<ol><li><a href='http://iloveco.de/user-content/' rel='bookmark' title='Permanent Link: I Love Code now featuring User Content!'>I Love Code now featuring User Content!</a> <small>As you may have noticed, the number of articles on...</small></li><li><a href='http://iloveco.de/hello-world/' rel='bookmark' title='Permanent Link: Hello world!'>Hello world!</a> <small>Welcome to I Love Code. I Love Code is a...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Hello!  As you may have noticed, the number of tutorials being published on the site has decreasing recently. This is because of the fact that a lot of our great <a href="http://iloveco.de/staff/">staff members</a> have been extremely busy recently with a lot of <a href="http://thoughtfultreesw.com/">exciting</a> <a href="http://yummycocoa.com">projects</a>! A lot of us, including yours truly, are currently very busy with Finals! We will try to publish as many tutorials as we can, but please bear with us. Things will pick back up in a month or so!</p>
<p>-Alex Nichols</p>


<p>Related posts:<ol><li><a href='http://iloveco.de/user-content/' rel='bookmark' title='Permanent Link: I Love Code now featuring User Content!'>I Love Code now featuring User Content!</a> <small>As you may have noticed, the number of articles on...</small></li><li><a href='http://iloveco.de/hello-world/' rel='bookmark' title='Permanent Link: Hello world!'>Hello world!</a> <small>Welcome to I Love Code. I Love Code is a...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/temporary-slow-down/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Post tweets through Applescript</title>
		<link>http://iloveco.de/how-to-post-tweets-through-applescript/</link>
		<comments>http://iloveco.de/how-to-post-tweets-through-applescript/#comments</comments>
		<pubDate>Tue, 26 May 2009 19:27:25 +0000</pubDate>
		<dc:creator>Collin Henderson</dc:creator>
		
		<category><![CDATA[Misc.]]></category>

		<guid isPermaLink="false">http://iloveco.de/?p=549</guid>
		<description><![CDATA[Hi there! This tutorial is going to show you how to post  &#8220;tweets&#8221; to Twitter. The following code comes directly from my ASTwitterLibrary, which is a complete library of methods for Applescript that you can use to interact with Twitter. 
Posting a tweet is very simple. First we need to set our username and [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Hi there! This tutorial is going to show you how to post  &#8220;tweets&#8221; to Twitter. The following code comes directly from my ASTwitterLibrary, which is a complete library of methods for Applescript that you can use to interact with Twitter. </p>
<p>Posting a tweet is very simple. First we need to set our username and password as properties. Let&#8217;s go ahead and do this.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">property</span> theUser : <span class="st0">&quot;usernamehere&quot;</span> <span class="co1">&#8211; your username</span><br />
<span class="kw1">property</span> thePassword : <span class="st0">&quot;passwordhere&quot;</span> <span class="co1">&#8211; your password</span></div>
</div>
<p>Now, since we are such nice tidy coders, and we appreciate convenience, we are going to put all of our main code in a method (or subroutine as some call it.) The reason for this is because it&#8217;s a chunk of code we could be calling over and over again and we want to make it easy to post the tweet. So, let us first create the methods name and add its parameters.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">on</span> postTweet<span class="br0">&#40;</span>theUser, thePassword, theMessage<span class="br0">&#41;</span><br />
<span class="co1">&#8211; Our code shall go here!!</span><br />
<span class="kw1">end</span> postTweet</div>
</div>
<p>Cool beans. So now we need to add some content to this method. We are simply going to use a cURL shell script to post our tweet. This will suffice. It sends a cURL call to Twitter&#8217;s update.xml file using the given username, password and message.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">on</span> postTweet<span class="br0">&#40;</span>theUser, thePassword, theMessage<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">set</span> TwitterUpdate <span class="kw1">to</span> <span class="st0">&quot;/usr/bin/curl&quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &#8211;user &quot;</span> &amp; quoted form <span class="kw1">of</span> <span class="br0">&#40;</span>theUser &amp; <span class="st0">&quot;:&quot;</span> &amp; thePassword<span class="br0">&#41;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &#8211;data status=&quot;</span> &amp; quoted form <span class="kw1">of</span> encodeURL<span class="br0">&#40;</span>theMessage<span class="br0">&#41;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; http://twitter.com/statuses/update.xml&quot;</span><br />
<span class="kw1">end</span> postTweet</div>
</div>
<p>Now you may have noticed a little method called in that shell script called encodeURL. This is a little method we must make to encode our URL before sending it with cURL. We&#8217;re going to call a little python script through a shell script to do this for us. Here&#8217;s the method.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">on</span> encodeURL<span class="br0">&#40;</span>someURL<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> do shell <span class="kw1">script</span> <span class="st0">&quot;/usr/bin/python -c &#8216;&quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;from sys import argv; &quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;from urllib import quote; &quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;print quote(unicode(argv[1], <span class="es0">\&quot;</span>utf8<span class="es0">\&quot;</span>))&#8217; &quot;</span> &amp; quoted form <span class="kw1">of</span> someURL<br />
<span class="kw1">end</span> encodeURL</div>
</div>
<p>Next we need to actually execute the shell script, and throw in a little error handler as well. </p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">on</span> postTweet<span class="br0">&#40;</span>theUser, thePassword, theMessage<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">set</span> TwitterUpdate <span class="kw1">to</span> <span class="st0">&quot;/usr/bin/curl&quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &#8211;user &quot;</span> &amp; quoted form <span class="kw1">of</span> <span class="br0">&#40;</span>theUser &amp; <span class="st0">&quot;:&quot;</span> &amp; thePassword<span class="br0">&#41;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &#8211;data status=&quot;</span> &amp; quoted form <span class="kw1">of</span> encodeURL<span class="br0">&#40;</span>theMessage<span class="br0">&#41;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; http://twitter.com/statuses/update.xml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">&#8211; Now try sending the Tweet to Twitter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">set</span> TwitterResponse <span class="kw1">to</span> do shell <span class="kw1">script</span> TwitterUpdate<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> TwitterResponse <span class="kw3">contains</span> <span class="st0">&quot;Could not authenticate&quot;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;Tweet failed to post. Your username or password may be incorrect, or Twitter might be expieriencing difficulties.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;Tweet successfully posted&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">end</span> <span class="kw1">if</span><br />
<span class="kw1">end</span> postTweet</div>
</div>
<p>And there you have it! Now if you want to post a tweet just call the method!</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">property</span> theUser : <span class="st0">&quot;usernamehere&quot;</span> <span class="co1">&#8211; your username</span><br />
<span class="kw1">property</span> thePassword : <span class="st0">&quot;passwordhere&quot;</span> <span class="co1">&#8211; your password</span><br />
<span class="kw1">on</span> postTweet<span class="br0">&#40;</span>theUser, thePassword, theMessage<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">set</span> TwitterUpdate <span class="kw1">to</span> <span class="st0">&quot;/usr/bin/curl&quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &#8211;user &quot;</span> &amp; quoted form <span class="kw1">of</span> <span class="br0">&#40;</span>theUser &amp; <span class="st0">&quot;:&quot;</span> &amp; thePassword<span class="br0">&#41;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; &#8211;data status=&quot;</span> &amp; quoted form <span class="kw1">of</span> encodeURL<span class="br0">&#40;</span>theMessage<span class="br0">&#41;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot; http://twitter.com/statuses/update.xml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">&#8211; Now try sending the Tweet to Twitter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">set</span> TwitterResponse <span class="kw1">to</span> do shell <span class="kw1">script</span> TwitterUpdate<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> TwitterResponse <span class="kw3">contains</span> <span class="st0">&quot;Could not authenticate&quot;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;Tweet failed to post. Your username or password may be incorrect, or Twitter might be expieriencing difficulties.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;Tweet successfully posted&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">end</span> <span class="kw1">if</span><br />
<span class="kw1">end</span> postTweet</p>
<p><span class="kw1">on</span> encodeURL<span class="br0">&#40;</span>someURL<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> do shell <span class="kw1">script</span> <span class="st0">&quot;/usr/bin/python -c &#8216;&quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;from sys import argv; &quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;from urllib import quote; &quot;</span> &amp; ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;print quote(unicode(argv[1], <span class="es0">\&quot;</span>utf8<span class="es0">\&quot;</span>))&#8217; &quot;</span> &amp; quoted form <span class="kw1">of</span> someURL<br />
<span class="kw1">end</span> encodeURL</p>
<p>
postTweet <span class="br0">&#40;</span>theUser, thePassword, <span class="st0">&quot;I&#8217;m posting this tweet through Applescript! Awesome!&quot;</span><span class="br0">&#41;</span></div>
</div>
<p>And that&#8217;s it! A simple way to post a tweet using Applescript and a clever little cURL call. Have fun!</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/how-to-post-tweets-through-applescript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Files and Collections</title>
		<link>http://iloveco.de/files-and-collections/</link>
		<comments>http://iloveco.de/files-and-collections/#comments</comments>
		<pubDate>Thu, 21 May 2009 16:19:15 +0000</pubDate>
		<dc:creator>Steven Degutis</dc:creator>
		
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://iloveco.de/wptest/?p=214</guid>
		<description><![CDATA[In this tutorial, we discuss Files and Collections. Specifically, we talk about Cocoa collection classes, property lists, and writing them to and reading them from files.
This episode is geared towards developers who already have an understanding of Cocoa objects, and are familiar with such basic concepts as NSString and text files.




Files and Collections from I [...]


Related posts:<ol><li><a href='http://iloveco.de/basic-c-programming-2/' rel='bookmark' title='Permanent Link: Basic C Programming'>Basic C Programming</a> <small>In This tutorial, we will look at the basic principles...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we discuss Files and Collections. Specifically, we talk about Cocoa collection classes, property lists, and writing them to and reading them from files.</p>
<p>This episode is geared towards developers who already have an understanding of Cocoa objects, and are familiar with such basic concepts as NSString and text files.</p>
<p><object width="600" height="400">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4622416&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4622416&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="600" height="400"></embed></object>
<p><a href="http://vimeo.com/4622416">Files and Collections</a> from <a href="http://vimeo.com/user525834">I Love Code</a> on <a href="http://vimeo.com">Vimeo</a>.</p>


<p>Related posts:<ol><li><a href='http://iloveco.de/basic-c-programming-2/' rel='bookmark' title='Permanent Link: Basic C Programming'>Basic C Programming</a> <small>In This tutorial, we will look at the basic principles...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://iloveco.de/files-and-collections/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
