<?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>Developing for iPhone</title>
	<atom:link href="http://www.developingforiphone.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.developingforiphone.com</link>
	<description>Learn how to create and develop iPhone applications from scratch.</description>
	<lastBuildDate>Sun, 26 Jul 2009 18:04:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tutorial 4-2: Keyboard Input</title>
		<link>http://www.developingforiphone.com/2009/07/tutorial-4-2-keyboard-input/</link>
		<comments>http://www.developingforiphone.com/2009/07/tutorial-4-2-keyboard-input/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 18:00:35 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[buttons]]></category>
		<category><![CDATA[flipside]]></category>
		<category><![CDATA[keybaord input]]></category>
		<category><![CDATA[number pad]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=142</guid>
		<description><![CDATA[Go ahead and open the Story Time project from the previous tutorial. In the resources folder, double-click &#8220;FlipsideView.xib&#8221; to open the interface for the application&#8217;s flipside view. This is where we will have a number of inputs to change the content of the story. By using Labels and Text Fields from the library in Interface [...]]]></description>
			<content:encoded><![CDATA[<p>Go ahead and open the Story Time project from the previous tutorial. In the resources folder, double-click &#8220;FlipsideView.xib&#8221; to open the interface for the application&#8217;s flipside view. This is where we will have a number of inputs to change the content of the story. By using Labels and Text Fields from the library in Interface Builder, create an interface that looks like this:</p>
<div id="attachment_149" class="wp-caption alignnone" style="width: 330px"><img class="size-full wp-image-149" title="Keyboard Input" src="http://www.developingforiphone.com/wp-content/uploads/2009/07/ss2.jpg" alt="iPhone Development Tutorials" width="320" height="502" /><p class="wp-caption-text">iPhone Development Tutorials</p></div>
<p><span id="more-142"></span></p>
<p></p>
<p>I changed the color and the size of the labels in the Attributes Inspector. For each text field, I added a default value. This can be added by entering some text in the &#8220;Text&#8221; field in the Attributes Inspector. Once this is done, save the interface and test the application. You may notice that you can&#8217;t get rid of the keyboard once you have finished entering text into a text field. One way of fixing this problem is by adding a big invisible button to the interface which will close the keyboard. When the user taps off the keyboard, the big button will be pressed and the keyboard will disappear.</p>
<p>Drag a Round Rect Button from the library to the view window. Now position and resize the button so it fills the entire interface. The interface should now look like this:</p>
<div id="attachment_151" class="wp-caption alignnone" style="width: 330px"><img class="size-full wp-image-151" title="Keyboard Inputs" src="http://www.developingforiphone.com/wp-content/uploads/2009/07/ss31.jpg" alt="ss3" width="320" height="502" /><p class="wp-caption-text">iPhone Development Tutorials</p></div>
<p>Next, select the big button you just created and click Layout &gt; Send To Back. Now the button will be behind all the other elements in the view. But we can still see it. Fix this by opening the Attributes Inspector with the button selected and change the Alpha value slider to 0.</p>
<p>Select the text box you created for the First Name label and in the Attributes Inspector, open up the capitalize drop down menu and select &#8220;Words&#8221;. This will cause the iPhone to automatically change the first letter of each word entered in that box to a capital letter. Do the same for the Last Name text box and the Title text box. Lastly, select the Number text box you created and in the Attributes Inspector, open up the Keyboard drop down menu and select &#8220;Number Pad&#8221;. This will ensure that the user can only enter numbers in this field.</p>
<p>Save your work and continue to the next tutorial where we will start adding some code to get our interface elements working.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/07/tutorial-4-2-keyboard-input/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial 4-1: Other Templates</title>
		<link>http://www.developingforiphone.com/2009/07/tutorial-4-1-other-templates/</link>
		<comments>http://www.developingforiphone.com/2009/07/tutorial-4-1-other-templates/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 15:42:56 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[3.0]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Utility Application]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=135</guid>
		<description><![CDATA[In the previous tutorial, we used a view-based application template. These consist of just one view or screen. Today, let&#8217;s try out a new template. Follow the instructions below to get started:
1. In XCode, click File &#62; New Project
2. In the left pane of the new window, click Application under the iPhone OS heading
3. In [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous tutorial, we used a view-based application template. These consist of just one view or screen. Today, let&#8217;s try out a new template. Follow the instructions below to get started:</p>
<p>1. In XCode, click File &gt; New Project<br />
2. In the left pane of the new window, click Application under the iPhone OS heading<br />
3. In the right pane, click Utility Application and then click the Choose button<br />
4. Name the project “Story Time” and click Save.</p>
<p>The Utility Application template we chose this time, sets up a nice flipping function for us. This means we can flip between two different views. Have a look at your new project window. You will notice that in the left pane, we have folder for the main view and a folder for the flipside view. Each of these folders contains some basic classes already set up for us. Now click on the Resources folder. You should see an interface file (.xib) for both the main view and the flipside view. Click &#8220;Build and Go&#8221; to test it out. Once the simulator is running, you can click the &#8220;i&#8221; icon at the bottom of the screen to flip over to the other view, then click the &#8220;Done&#8221; button to flip back. Cool huh?</p>
<p><span id="more-135"></span></p>
<p></p>
<p><em>On a side note, you should have updated to the latest version of the iPhone SDK for iPhone 3.0. If you have not done this, make sure you do before continuing.</em></p>
<p>Back in XCode, open MainView.xib in the Resources folder. This will open the interface builder ready to edit the main view. You will notice that the &#8220;i&#8221; icon is already there and set up for you. We will leave this where it is for this tutorial. At the end of this set of tutorials, we will have created a story-telling app which displays a story that the user can edit.</p>
<p>In Interface Builder, click the background and change it&#8217;s color to white in the Attributes Inspector. You may notice that it is now hard to see the &#8220;i&#8221; icon. Let&#8217;s change that: select the icon then in the Attributes Inspector, change its &#8220;Type&#8221; from &#8220;Info Light&#8221; to &#8220;Info Dark&#8221;. Now grab the Text View item from the library and drag it onto your View. Resize it so it fills up most of the view. This will be our story. Drag a label item from the library and position it above the text we just added. This will be the title of the story. Resize and position it however you want. Here is how mine looks:</p>
<p><img class="alignleft size-full wp-image-136" title="iPhone Tutorials" src="http://www.developingforiphone.com/wp-content/uploads/2009/07/ss1.tiff" alt="Screenshot from iPhone development tutorial" /></p>
<p>Save this interface and click &#8220;Build and Go&#8221; in XCode to try it out. Notice that it automatically scrolls the text when you flick it &#8211; no coding required! Clicking the &#8220;i&#8221; icon flips to the other view seamlessly. In the other view, we will add some input boxes to change the story. We will be adding these in the <a title="Keyboard Input" href="http://www.developingforiphone.com/2009/07/tutorial-4-2-keyboard-input/" target="_self">next tutorial</a>. Remember to save your work before proceeding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/07/tutorial-4-1-other-templates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial 3-3: More Interface Connections</title>
		<link>http://www.developingforiphone.com/2009/05/tutorial-3-3-more-interface-connections/</link>
		<comments>http://www.developingforiphone.com/2009/05/tutorial-3-3-more-interface-connections/#comments</comments>
		<pubDate>Sat, 02 May 2009 22:02:14 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[label]]></category>
		<category><![CDATA[outlet]]></category>
		<category><![CDATA[Slider]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=122</guid>
		<description><![CDATA[Go ahead and open the &#8220;HelloiPhone&#8221; project from the previous tutorial. Remember the slider we added to the interface? Today we will give it some functionality.
Open &#8220;HelloiPhoneViewController.h&#8221; and edit it to look like this:

#import &#60;UIKit/UIKit.h&#62;
&#160;
@interface HelloiPhoneViewController : UIViewController &#123;
	IBOutlet UILabel *sliderValue;
&#125;
&#160;
@property &#40;nonatomic, retain&#41; UILabel *sliderValue;
&#160;
-&#40;IBAction&#41; sliderChanged: &#40;id&#41; s;
-&#40;IBAction&#41; goButton;
&#160;
@end



So what have we done? We have [...]]]></description>
			<content:encoded><![CDATA[<p>Go ahead and open the &#8220;HelloiPhone&#8221; project from the previous tutorial. Remember the slider we added to the interface? Today we will give it some functionality.<br />
Open &#8220;HelloiPhoneViewController.h&#8221; and edit it to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> HelloiPhoneViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	IBOutlet UILabel <span style="color: #002200;">*</span>sliderValue;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> UILabel <span style="color: #002200;">*</span>sliderValue;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> sliderChanged<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> s;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> goButton;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><span id="more-122"></span></p>
<p></p>
<p>So what have we done? We have created an <strong>outlet</strong> called sliderValue. Outlets send data back to the interface. In this case, we will be sending the value of the slider to the label we created. We also added the @property function to help us retrieve and set the value of sliderValue (our label). Remember that @ property and @synthesize work together to simulate getter and setter methods. For now, ignore &#8220;(nonatomic, retain)&#8221; you don&#8217;t need to know about this yet.<br />
Then we create a new method that will be called sliderChanged that will be run whenever the user interacts with the slider. Notice that we have told this method to accept an argument that it will store in the variable &#8220;s&#8221;. The variable type is &#8220;id&#8221; &#8211; this is a generic variable so it can accept any variable type. If we had used &#8220;int&#8221; instead it would have only been able to accept integer variables.</p>
<p>With that done, time to move over to the implementation file. Save &#8220;HelloiPhoneViewController.h&#8221; and open &#8220;HelloiPhoneViewController.m&#8221;. First of all we need to synthesize the sliderValue variable. so add this line after the &#8220;@implementation&#8221; line:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> sliderValue;</pre></div></div>

<p>Now lets add the &#8220;sliderChanged&#8221; method below:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span>sliderChanged<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> s <span style="color: #002200;">&#123;</span>
	UISlider <span style="color: #002200;">*</span>slider <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UISlider <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> s;
	<span style="color: #a61390;">float</span> sliderPosition <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>slider.value<span style="color: #002200;">&#41;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithFormat<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%0.1f&quot;</span>, sliderPosition<span style="color: #002200;">&#93;</span>;
	sliderValue.text <span style="color: #002200;">=</span> text;
	<span style="color: #002200;">&#91;</span>text release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Let&#8217;s have a look at what we did here.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UISlider <span style="color: #002200;">*</span>slider <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UISlider <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> s;</pre></div></div>

<p>Here we created a new UISlider object from Apple&#8217;s UISlider class and called it &#8220;slider&#8221;. We then told it to store the slider that is passed into the method. (that would be the slider we created in the previous tutorial.)</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">float</span> sliderPosition <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>slider.value<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>Here we created a <strong>float</strong> variable called sliderPosition. Float stands for &#8220;Floating-point&#8221; and it&#8217;s a type of variable that holds digits just like the int variable does &#8211; however, a float variable can store a decimal point whereas an int can&#8217;t. If you tried to store the number &#8220;27.8&#8243; in an int variable, the decimal would be cut off and it would return &#8220;27&#8243;. Note that it doesn&#8217;t round the number up or down, it just cuts the decimal places off. There are many types of variable that you will learn about as we go.<br />
We then store the value of our slider in the variable.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithFormat<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%0.1f&quot;</span>, sliderPosition<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Now we create a new object called &#8220;text&#8221;. This is an NSString object. It is used to store strings (text) because there isn&#8217;t a variable type in Objective-C that does this. We then initialize it and use &#8220;%f&#8221; to tell it to store the sliderPosition float after the comma. However, by inserting &#8220;0.1&#8243; before the &#8220;f&#8221;, we are telling it to only store one decimal place. You may remember doing something like this when printing using the NSLog method.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">sliderValue.text <span style="color: #002200;">=</span> text;
<span style="color: #002200;">&#91;</span>text release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Then we pass the nicely formatted NSString object to our label using &#8220;sliderValue.text&#8221; and release the &#8220;text&#8221; object from memory.</p>
<p>Make sure you understand what we have done here before you move on.<br />
Save &#8220;HelloiPhoneViewController.m&#8221; and return to the project window. Click the Resources folder and double-click the &#8220;HelloiPhoneViewController.xib&#8221; file to open the Interface Builder.<br />
Now let&#8217;s connect up the slider and the label with the code we just wrote. Click the slider you placed on your interface to select it and open the Connections Inspector. (Tools > Connections Inspector)<br />
Now grab the circle next to &#8220;Value Changed&#8221; and drag a line over to the &#8220;Files Owner&#8221; icon. In the menu that pops up, click the &#8220;sliderChanged:&#8221; option. This is the same thing we did with the button in the last tutorial, but now we are using our &#8220;sliderChanged&#8221; method. Now the slider will change the value of &#8220;sliderValue&#8221; but we want this value to appear in the label below. Here is how to do that:<br />
Hold down the control(⌃) key on the keyboard and drag a line from the &#8220;File Owner&#8221; icon to the &#8220;0.5&#8243; label you added last time. A menu should pop up with two options (sliderValue and view). Click sliderValue and hey presto, the label will now update every time the slider is moved. Save the file and test it out! Dragging the slider to the left should cycle the number down to 0 and the the right should cycle it up to 1.</p>
<p>Great work! Save the project and proceed to the <a href="http://www.developingforiphone.com/2009/07/tutorial-4-1-other-templates/">next tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/05/tutorial-3-3-more-interface-connections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tutorial 3-2: Interface Connections</title>
		<link>http://www.developingforiphone.com/2009/05/tutorial-3-2-interface-connections/</link>
		<comments>http://www.developingforiphone.com/2009/05/tutorial-3-2-interface-connections/#comments</comments>
		<pubDate>Fri, 01 May 2009 22:08:37 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[Slider]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=112</guid>
		<description><![CDATA[Open the &#8220;HelloiPhone&#8221; project we worked on in the previous tutorial.
Today we will start by adding a button to our interface. So click the Resources folder in the project window and double click &#8220;HelloiPhoneViewController.xib&#8221; to open the Interface Builder. We already have a label set up, so let&#8217;s add a button below it. In Interface [...]]]></description>
			<content:encoded><![CDATA[<p>Open the &#8220;HelloiPhone&#8221; project we worked on in the previous tutorial.</p>
<p>Today we will start by adding a button to our interface. So click the Resources folder in the project window and double click &#8220;HelloiPhoneViewController.xib&#8221; to open the Interface Builder. We already have a label set up, so let&#8217;s add a button below it. In Interface Builder, select &#8220;Round Rect Button&#8221; in the Library window and drag it onto your view just below the label we created. Double click on your new button and type in &#8220;GO&#8221;. Feel free to move or resize the button however you want. You can resize using the blue dots when the button is selected. When you are happy with your button, proceed to the next step.</p>
<p>We have a button now, but it doesn&#8217;t do anything yet. Let&#8217;s add a slider and then we can add functionality to them later. Drag a &#8220;Silder&#8221; from the Library window to your view somewhere below the button. Resize it to fill the width of the view. Now drag another &#8220;Label&#8221; from the Library and place it below the slider. This label will change when the slider is moved with the help of some code. Change the label to say &#8220;0.5&#8243;. When the slider is to the left, we will set the slider label to 0 and set it to 1 when it is to the right. Since we are initializing the slider in the middle, the label should initially read 0.5. Highlight the new label and set the alignment to the center. This can be done in the Attributes Inspector. Your interface should now look something like this:</p>
<p><span id="more-112"></span></p>
<p style="text-align: center;"><img class="size-medium wp-image-113 aligncenter" title="3-2-screenshot1" src="http://www.developingforiphone.com/wp-content/uploads/2009/05/picture-1-191x300.png" alt="Create iPhone Applications" width="191" height="300" /></p>
<p>Let&#8217;s add some functionality to our interface.</p>
<p></p>
<p>Save your interface in Interface Builder by clicking File > Save. Now switch back to XCode and open &#8220;HelloiPhoneViewController.h&#8221; for editing. It is located in the Classes folder.<br />
By now you should understand how to create a basic Objective-C application. If you don&#8217;t please read through the previous tutorials. Edit &#8220;HelloiPhoneViewController.h&#8221; to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> HelloiPhoneViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> goButton;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>We have created a new method called goButton. But notice that instead of using &#8220;void&#8221;, we used &#8220;IBAction&#8221;. This is simply telling the compiler that we are returning an Interface Builder action. We will run the goButton method whenever the GO button we created is tapped.<br />
Save the file and open &#8220;HelloiPhoneViewController.m&#8221; to fill out the method we created. You may notice that there is already some methods defined, some of them commented out. Leave them as they are for now, and add the following code for the goButton method:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> goButton <span style="color: #002200;">&#123;</span>
	UIAlertView <span style="color: #002200;">*</span>alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Button Pressed&quot;</span> 
	message<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;You pressed the GO button!&quot;</span>
	delegate<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span>
	cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;OK&quot;</span>
	otherButtonTitles<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Lets look at what we did here:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIAlertView <span style="color: #002200;">*</span>alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Button Pressed&quot;</span></pre></div></div>

<p>In this line we created an object called &#8220;alert&#8221; from the UIAlertView class. (this is a class that apple have written for us to handle alerts.) We then allocated a space in the memory for it using alloc and then initialized it with the title &#8220;Button Pressed&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">message<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;You pressed the GO button!&quot;</span></pre></div></div>

<p>This line set the message that we will display to the user in the alert.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">delegate<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span>
cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;OK&quot;</span>
otherButtonTitles<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>We then used cancelButtonTitle to create a button on the alert box and set the button&#8217;s text to &#8220;OK&#8221;. We used a Cancel button because it will simply remove the alert box from the screen when pressed. OtherButtonTitles is set to nil because we dont want any more buttons in the alert box. You don&#8217;t have to worry about the delegate setting for now.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Then we ran a method from the UIAlertView class called &#8220;show&#8221; which shows the alert to the user, then we released the alert object from the memory. Memory management is important. Everything you load into memory should be removed when finished with. The iPhone only has a limited amount of memory available, so you have to use it wisely.<br />
Make sure you understand what we did, and save the file.</p>
<p>Now we have the alert set up, let&#8217;s link the GO button to the goButton method so the alert is activated when the button is tapped. Switch back to Interface Builder. Click the GO button in your view window. Now open the Connections Inspector. This can be done by clicking Tools > Connections Inspector. Notice that the Connections Inspector uses the same window as the Attributes Inspector. They can be switched between using the tabs at the top of the window or by using the keyboard shortcuts.</p>
<p>In the Connections Inspector you will notice a list of actions that can be performed on the button. The one we want to use is &#8220;Touch Up Inside&#8221;. This means when the user&#8217;s finger leaves the button. Drag a line from the circle next to &#8220;Touch Up Inside&#8221; over to the &#8220;File&#8217;s Owner&#8221; icon in the HelloiPhoneViewController.xib window. Release the mouse and a menu should pop up with our goButton method listed. Click it to assign that method to the button&#8217;s action. The Connections Inspector should now have the goButton method listed under the &#8220;Touch Up Inside&#8221; event. Save the interface and switch back to XCode.</p>
<p>Great! Now we have created a button, created a method that will be run when the button is tapped and connected the two together! That wasn&#8217;t too hard was it? Now click Build and Run to test it out! Clicking the button will show the alert we created, but moving the slider won&#8217;t do much. We will add some functionality to the slider in the <a href="http://www.developingforiphone.com/2009/05/tutorial-3-3-more-interface-connections/">next tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/05/tutorial-3-2-interface-connections/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to develop iPhone applications on Windows</title>
		<link>http://www.developingforiphone.com/2009/04/how-to-develop-iphone-applications-on-windows/</link>
		<comments>http://www.developingforiphone.com/2009/04/how-to-develop-iphone-applications-on-windows/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 01:38:16 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Create iPhone Applications]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=110</guid>
		<description><![CDATA[I see a lot of people asking this question.
The simple answer is you can&#8217;t. Not at the moment anyway, and there aren&#8217;t any signs on the horizon either. You wouldn&#8217;t expect Microsoft to allow Mac users to develop XNA games on the Mac would you? Of course, it would be nice. As a primary Windows [...]]]></description>
			<content:encoded><![CDATA[<p>I see a lot of people asking this question.</p>
<p>The simple answer is you can&#8217;t. Not at the moment anyway, and there aren&#8217;t any signs on the horizon either. You wouldn&#8217;t expect Microsoft to allow Mac users to develop XNA games on the Mac would you? Of course, it would be nice. As a primary Windows user myself, I would rather be creating developing iPhone applications in the familiar Windows environment, but it&#8217;s just one of those things.</p>
<p>However, don&#8217;t be put off by the price of a Mac. The Mac Mini may not be as powerful the iMac or Mac Pro, but its cheap and you dont need much power if you are developing iPhone applications. A Mac Mini has more than enough horse-power for that. On top of that the iPhone SDK (software development kit) is absolutely free!</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/04/how-to-develop-iphone-applications-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial 3-1: Hello iPhone!</title>
		<link>http://www.developingforiphone.com/2009/04/tutorial-3-1-hello-iphone/</link>
		<comments>http://www.developingforiphone.com/2009/04/tutorial-3-1-hello-iphone/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 23:19:21 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[beginners]]></category>
		<category><![CDATA[Create iPhone Applications]]></category>
		<category><![CDATA[interface builder]]></category>
		<category><![CDATA[label]]></category>
		<category><![CDATA[simulator]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=103</guid>
		<description><![CDATA[Ah yes, the moment you have been waiting for. Time to write an iPhone application. If you have not completed the previous tutorials, I suggest you do that now.
Follow these steps to get started:

In XCode, click File &#62; New Project
In the left pane of the new window, click Application under the iPhone OS heading
In the [...]]]></description>
			<content:encoded><![CDATA[<p>Ah yes, the moment you have been waiting for. Time to write an <strong>iPhone application</strong>. If you have not completed the previous tutorials, I suggest you do that now.<br />
Follow these steps to get started:</p>
<ol>
<li>In XCode, click File &gt; New Project</li>
<li>In the left pane of the new window, click Application under the iPhone OS heading</li>
<li>In the right pane, click View Based Application and then click the Choose button</li>
<li>Name the project &#8220;HelloiPhone&#8221; and click Save</li>
</ol>
<p>You will notice that there are a few folders set up for you in the left pane of the project window. For now you don&#8217;t need to know what all the files in each folder do.<br />
Click Build and Go. A new application will open called iPhone Simulator, and in it comes a nice shiny iPhone for you to play with. This is where you can test your applications. As soon as it loads, it will boot up the application that you just created. You haven&#8217;t done anything to it yet so it is just a gray screen. Press the home button (the square symbol at the bottom) to exit the application. Go ahead and play around with it &#8211; use it just like a real iphone but use your mouse to control it instead. Try clicking Hardware > Rotate Left or Right to flip the iPhone on it&#8217;s side.</p>
<p>There are some things that the iPhone simulator can&#8217;t do. It doesn&#8217;t include things like GPS to find it&#8217;s location or an accelerometer to detect movement or tilting. You also cant use multi-touch as you only have one mouse. For these things you will need to test on a real iPhone. However, you are only allowed to use a real iPhone if you have paid for and been accepted to Apple&#8217;s Standard Developer Program or higher. But for learning the basics, the simulator is fine.</p>
<p>Quit the simulator when you are done and return to XCode.</p>
<p><span id="more-103"></span></p>
<p></p>
<p>In the left pane of the project window, click the Resources folder and in the right pane, double-click &#8220;HelloiPhoneViewController.xib&#8221;. Another new application will open. This application is called Interface Builder and it is what we will use to design and lay out our interfaces. When developing iPhone applications, the three applications: XCode, Interface Builder and iPhone Simulator work together to help you easily and efficiently create iPhone applications.</p>
<p>When Interface Builder is open, you should be presented with three windows. One named after the file we just opened, one called View and one called Library. For now, let&#8217;s just worry about the View and Library windows. The view window represents your application interface. At the moment it is gray, just as you saw it on the iPhone Simulator. The library contains all the interface elements that Apple have designed for you.</p>
<p>Let&#8217;s go ahead and make our interface less boring. In the Library window, scroll down to Label, then drag and drop it into the View window. It is all pretty intuitive. Double click the text once it is in the View and change it to say: &#8220;Hello iPhone!&#8221;. Press the Enter or Return key to confirm. Now let&#8217;s say we want the text to be a little bit bigger and white. No problem. In the menu bar, click Tools > Attribute Inspector. This will open a fourth window. Using the Attribute Inspector window, you can edit the appearance of elements.</p>
<p>With the text label still selected, change the Font Size value in the Attribute inspector to 25. You may notice that some of the text was cut off when it got bigger. So just grab one of the blue corner dots surrounding the text and drag it to make the Label big enough to display all the text.</p>
<p>In the Attribute Inspector, click the Text color box (black at the moment) and in the Colors window that appears, click the top (white) area of the vertical slider. Close the Color window and the Attribute Inspector. Now click and drag the Label in the View window to position it nicely in the middle. There! All done! Let&#8217;s go ahead and test our first iPhone application! </p>
<p>Click File > Save to save the interface file, then switch back to XCode and click Build and Go to test it in the iPhone simulator.</p>
<p>Great stuff! We did all that without having to enter a single line of code! Why don&#8217;t you switch back to the Interface Inspector and play around with the Attributes Inspector to change the appearance of the Label we created. In the next tutorial we will be trying out some of the other iPhone interface elements from the Library. <a href="http://www.developingforiphone.com/2009/05/tutorial-3-2-interface-connections/">Click here</a> to head there now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/04/tutorial-3-1-hello-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial 2-4: Inheritance</title>
		<link>http://www.developingforiphone.com/2009/04/tutorial-2-4-inheritance/</link>
		<comments>http://www.developingforiphone.com/2009/04/tutorial-2-4-inheritance/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 19:52:44 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[child]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[subclass]]></category>
		<category><![CDATA[superclass]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=96</guid>
		<description><![CDATA[Another reason object-oriented programming languages are so powerful is inheritance. Inheritance lets a class inherit methods and variables from another class. To demonstrate this, let&#8217;s make a new class that will inherit the Television class we already created. Open your &#8220;Objects Intro&#8221; project and click File > New File. Select Cocoa from the left pane [...]]]></description>
			<content:encoded><![CDATA[<p>Another reason object-oriented programming languages are so powerful is inheritance. Inheritance lets a class inherit methods and variables from another class. To demonstrate this, let&#8217;s make a new class that will inherit the Television class we already created. Open your &#8220;Objects Intro&#8221; project and click File > New File. Select Cocoa from the left pane and Objective-c Class from the right pane. Click next and name it &#8220;MutableTelevision.m&#8221; (make sure &#8220;create .h&#8221; box is ticked) then click Finish.</p>
<p>Ok, now we have two classes in our project. &#8220;Television&#8221; and &#8220;MutableTelevision&#8221;. The Television class does the basic things that we would expect a television to do. But what if we want a class that does all that but has extra features? We could write all the methods again for the new class, but an easier option would be to use inheritance and make MutableTelevision a child of Television.</p>
<p>Open &#8220;MutableTelevision.h&#8221; and let&#8217;s start creating the interface file. Edit it to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Cocoa/Cocoa.h&gt;</span>
<span style="color: #6e371a;">#import &quot;Television.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MutableTelevision <span style="color: #002200;">:</span> Television
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> mute;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><span id="more-96"></span></p>
<p></p>
<p>Let&#8217;s look at what we did. First, as always, we tell the compiler that we are creating an interface file, then we name it. But then we tell it that the Television class is the parent of this class by using the : operator. Notice that you need to import the parent class. Look at &#8220;Telelvision.h&#8221; again &#8211; you will notice that we seem to have inherited a class called NSObject. We didn&#8217;t create that class, it is already set up for us by Apple. You don&#8217;t need to understand everything this class does, but we have used one of it&#8217;s methods before. The NSLog method for printing text to the console is simply a method from the NSObject class.</p>
<p>Another name for parent and child classes is superclasses and subclasses. They mean the same thing &#8211; but it is useful to know both terms. So, we know that MutableTelevision is a child (or subclass) of Television, and Television is a child (or subclass) of NSObject. Even though MutableTelevision does not directly inherit NSObject, it inherits everything in the Television class including it&#8217;s parent class (or superclass), NSObject. We did not define any instance variables because the channel variable is already inherited from Television.</p>
<p>Once you understand this, save &#8220;MutableTelevision.h&#8221; and open &#8220;MutableTelevision.m&#8221; to fill out that mute method. Edit the file to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;MutableTelevision.h&quot;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@implementation</span> MutableTelevision
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> mute <span style="color: #002200;">&#123;</span>
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;The TV is now on mute.&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>A very simple method here that just prints a message to the console. Save and close &#8220;MutableTelevision.h&#8221;, then open &#8220;Objects Intro.m&#8221;. Edit it to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
<span style="color: #6e371a;">#import &quot;MutableTelevision.h&quot;</span>
&nbsp;
<span style="color: #a61390;">int</span> main <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span> argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSAutoreleasePool</span> <span style="color: #002200;">*</span> pool <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAutoreleasePool</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">int</span> chanChange;
&nbsp;
	MutableTelevision <span style="color: #002200;">*</span>myTV <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MutableTelevision alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Type in the channel number:&quot;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">scanf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;%i&quot;</span>, <span style="color: #002200;">&amp;</span>chanChange<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>myTV changeChannel<span style="color: #002200;">:</span> chanChange<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myTV mute<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>myTV release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>pool drain<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The main changes here are the import statements importing &#8220;MutableTelevision.h&#8221; instead of &#8220;Television.h&#8221; and the creation of the MutableTelevision object. Notice that we are still using the name myTV as the object name, except now the object is created by the MutableTelevision class rather than the Television class. Run the program to test it out with the new mute method. You may notice that the changeChannel method worked even though we didn&#8217;t define it in &#8220;MutableTelevision&#8221;. This is because MutableTelevision has inherited all the methods and variables from the Television class. If we tried to use the mute method with a Television object however, it wouldn&#8217;t work because there is no mute method in the Television class or in any class above it in the hierarchy.</p>
<p>We still have a lot to learn about Objective-C, but you are probably hoping to start working with the iPhone interface. So in our next tutorials I will introduce development in the iPhone environment while introducing more Objective-C concepts as we go. Play around with what you have learned so far.</p>
<p>When you are ready, move on to the <a href="http://www.developingforiphone.com/2009/04/tutorial-3-1-hello-iphone/">next tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/04/tutorial-2-4-inheritance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial 2-3: The if Statement</title>
		<link>http://www.developingforiphone.com/2009/04/tutorial-2-3-the-if-statement/</link>
		<comments>http://www.developingforiphone.com/2009/04/tutorial-2-3-the-if-statement/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 15:03:53 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[else]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[scanf]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=89</guid>
		<description><![CDATA[Let&#8217;s start by opening the &#8220;Objects Intro&#8221; project from the last tutorial. If you haven&#8217;t done so already, I strongly recommend that you add some comments to the code you have written so far which explain what each part does.
Once you have done that, open &#8220;Objects Intro.m&#8221; and edit it to look like this:

#import &#60;Foundation/Foundation.h&#62;
#import [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s start by opening the &#8220;Objects Intro&#8221; project from the last tutorial. If you haven&#8217;t done so already, I strongly recommend that you add some comments to the code you have written so far which explain what each part does.</p>
<p>Once you have done that, open &#8220;Objects Intro.m&#8221; and edit it to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
<span style="color: #6e371a;">#import &quot;Television.h&quot;</span>
&nbsp;
<span style="color: #a61390;">int</span> main <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span> argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSAutoreleasePool</span> <span style="color: #002200;">*</span> pool <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAutoreleasePool</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">int</span> chanChange;
&nbsp;
	Television <span style="color: #002200;">*</span>myTV <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Television alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Type in the channel number:&quot;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">scanf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;%i&quot;</span>, <span style="color: #002200;">&amp;</span>chanChange<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>myTV changeChannel<span style="color: #002200;">:</span> chanChange<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myTV watch<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>myTV release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>pool drain<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><span id="more-89"></span></p>
<p></p>
<p>Let&#8217;s look at what we did. First we created an integer variable called &#8220;chanChange&#8221;. Then we asked the user to enter a number. The scanf function is used to accept user input from the console. So we tell scanf that we are expecting an integer using &#8220;%i&#8221; and then specify the variable to store it in: &#8220;&#038;changeChan&#8221;. Then as before, we call the &#8220;changeChannel&#8221; method and pass the &#8220;chanChange&#8221; variable into it. The &#8220;watch&#8221; method is then called to print out whatever channel number the user entered.</p>
<p>Easy huh? Now let&#8217;s say that the television only has 10 channels. If the user enters a channel number higher than 10, we want to tell them that the channel doesn&#8217;t exist. Save &#8220;Objects Intro.m&#8221; and open &#8220;Television.m&#8221;. Edit the &#8220;changeChannel&#8221; method to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> changeChannel<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> c <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>c &gt; <span style="color: #2400d9;">10</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		channel <span style="color: #002200;">=</span> c;
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;You are watching channel %i&quot;</span>, channel<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Sorry, this channel doesn't exist.&quot;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>If you have used programming languages before, you will probably recognize the if statement. What we have said here is: &#8220;if the channel number (c) is greater than 10, change the channel to that number and print a confirmation message, otherwise (else) print an error message.&#8221; So if the condition within the brackets is met, the statements within the following curly brackets are executed. If the condition is not met, the statements after &#8220;else&#8221; are executed. Make sure you understand this before we move on.</p>
<p>Now that the &#8220;changeChannel&#8221; method does what the &#8220;watch&#8221; method already did, we have no need for the &#8220;watch&#8221; method any more. So go ahead and delete the entire &#8220;watch&#8221; method. Once this is done you should only have two methods left. &#8220;turnOff&#8221; and &#8220;changeChannel&#8221;. Save &#8220;Television.m&#8221; and open &#8220;Television.h&#8221;. Now go ahead and delete the line that declares the &#8220;watch&#8221; method here too &#8211; otherwise the compiler will throw an error. Save &#8220;Television.h&#8221; and open &#8220;Objects Intro.m&#8221;.</p>
<p>Delete the following line from &#8220;Objects Intro.m&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>myTV watch<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Now save and run your program. After being asked to type in the channel number, type in a number from 1 to 10 and press Enter or Return. If everything went well, it should then print out the confirmation statement you wrote. Now run the program again and enter a number higher than 10.</p>
<p>Great work! Save the project and proceed to the <a href="http://www.developingforiphone.com/2009/04/tutorial-2-4-inheritance/">next tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/04/tutorial-2-3-the-if-statement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial 2-2: Properties and Accessor Methods</title>
		<link>http://www.developingforiphone.com/2009/04/tutorial-2-2-properties-and-accessor-methods/</link>
		<comments>http://www.developingforiphone.com/2009/04/tutorial-2-2-properties-and-accessor-methods/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 23:12:49 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[getter and setter]]></category>
		<category><![CDATA[instance variables]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[synthesize]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=76</guid>
		<description><![CDATA[In this tutorial, we will need to use the project that we started in the last tutorial. So go ahead and open your &#8220;Objects Intro&#8221; project.
If you remember, last time we created the Television class which we used to create a Television object which could print out two different statements. Today we will add a [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we will need to use the project that we started in the last tutorial. So go ahead and open your &#8220;Objects Intro&#8221; project.</p>
<p>If you remember, last time we created the Television class which we used to create a Television object which could print out two different statements. Today we will add a new method that will change the channel of the television. To do this the television needs to be able to store some data. Let&#8217;s go ahead and create a space to store that data now. Open &#8220;Television.h&#8221; and edit the empty brackets to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> Television <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> channel;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>We have now got an <strong>instance</strong> variable in which to store the channel number. An instance variable is data held by an object. For example, if we created two Television objects from the Television class, we could set the channel number of myTV1 to 3, and the channel number of myTV2 to 7. Both Televisions are produced by the Television class, but each can store their own data.  But how do we change the channel? This is where <strong>Accessor Methods</strong> come in.</p>
<p><span id="more-76"></span></p>
<p></p>
<p>Accessor methods (otherwise known as <em>Getter and Setter</em> methods) are used to modify the variables held by an object. It may be hard to get your head round how they work at the moment &#8211; but stick with me &#8211; the more we use them, the more you will understand them.</p>
<p>In some programming languages, you have to write your accessor methods yourself &#8211; but in Objective-C, they can be generated automatically by using @property and @synthesize. Let&#8217;s not worry about what these do for the moment &#8211; just know that @property belongs in the interface file and @synthesize belongs in the implementation file. Together, they can be used to modify your instance variables. Let&#8217;s add them now. Add the @property statement to &#8220;Television.h&#8221; so it looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Cocoa/Cocoa.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@interface</span> Television <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> channel;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #a61390;">int</span> channel;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> watch;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> turnOff;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>When using the @ property statement, you must tell the compiler what type of variable it is and the name of the variable(s) to be changed. Now the channel variable can be modified, we need a method that we will use to modify it. Let&#8217;s call that method <strong>changeChannel</strong>. So add this line below the turnOff method:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> changeChannel<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> c;</pre></div></div>

<p>You may notice that this method declaration looks a little different to the others. This is because it takes an argument. By doing this we can pass a variable into the method when we invoke (or call) it. So this method takes an integer variable which is temporarily named &#8220;c&#8221;. This will become clearer as we continue with this tutorial.</p>
<p>We are finished with the interface file for now, so save it and open &#8220;Television.m&#8221; (the implementation file) to flesh out that new method.<br />
Wait. Before we touch the changeChannel method, we need to add the @synthesizer statement so we can change that channel variable in the interface file. Add the following line below <code>@implementation Television</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> channel;</pre></div></div>

<p>Great. With that done, we can start editing the changeChannel method. Add the following method below the other two:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> changeChannel<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> c <span style="color: #002200;">&#123;</span>
	channel <span style="color: #002200;">=</span> c;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>That was pretty easy right? Any variable passed into that method will be stored in &#8220;c&#8221; &#8211; then we set the value of the &#8220;channel&#8221; instance variable to the integer stored in &#8220;c&#8221;. Now our television can change channel! But wait! How are we going to know what channel we are watching if it&#8217;s not a real TV? Change the &#8220;watch&#8221; method so it looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> watch <span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;You are watching channel %i&quot;</span>, channel<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Simple we just altered the output of the watch method so it tells us what channel we are currently watching. We are now ready to use our TV. Save and close &#8220;Television.m&#8221; and open &#8220;Objects Intro.m&#8221;. Edit the file to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
<span style="color: #6e371a;">#import &quot;Television.h&quot;</span>
&nbsp;
<span style="color: #a61390;">int</span> main <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span> argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSAutoreleasePool</span> <span style="color: #002200;">*</span> pool <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAutoreleasePool</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	Television <span style="color: #002200;">*</span>myTV <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Television alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>myTV changeChannel<span style="color: #002200;">:</span> <span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myTV watch<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>myTV release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>pool drain<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>All we did is call the method &#8220;changeChannel&#8221; with 4 as an argument (remember, we are passing the number 4 into the method), and then we called the &#8220;watch&#8221; method to display the value of channel. Save and run the program to see the result. (remember to open the console using Run > Console).</p>
<p> &#8220;channel&#8221; is now a property of the television object. We can access properties like this: <code>object.property</code></p>
<p>Delete this line:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>myTV watch<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>and replace it with this line:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;You are watching channel %i&quot;</span>, myTV.channel<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>Now run the program again. The same result! myTV.channel gets the value of &#8220;channel&#8221; from your myTV object. You can even set the value of properties this way. Delete this line:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>myTV changeChannel<span style="color: #002200;">:</span> <span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>and replace it with this line:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">myTV.channel <span style="color: #002200;">=</span> <span style="color: #2400d9;">7</span>;</pre></div></div>

<p>Now build and run again. This does exactly the same function as the changeChannel method does, but with much less code! It is still important that we wrote the changeChannel method though &#8211; to show you how to pass variables into a method. We could delete changeChannel now, but we will leave it as we will be modifying it in an upcoming tutorial.</p>
<p>Once you are confident that you understand what we have done today, head over to the <a href="http://www.developingforiphone.com/2009/04/tutorial-2-3-the-if-statement/">next tutorial</a> now.<br />
Remember, if you spot any mistakes PLEASE point them out to me. Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/04/tutorial-2-2-properties-and-accessor-methods/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial 2-1: Introduction to Object Oriented Programming</title>
		<link>http://www.developingforiphone.com/2009/04/tutorial-2-1-introduction-to-object-oriented-programming/</link>
		<comments>http://www.developingforiphone.com/2009/04/tutorial-2-1-introduction-to-object-oriented-programming/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 21:02:12 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[Methods]]></category>
		<category><![CDATA[Object Oriented]]></category>

		<guid isPermaLink="false">http://www.developingforiphone.com/?p=59</guid>
		<description><![CDATA[I know you are probably itching to get stuck into the iPhone programming environment, but there are a few things you HAVE to learn first. One of them is Object Oriented Programming. The reason I am jumping right into this is that it is the main feature of Objective-C and a very powerful set of [...]]]></description>
			<content:encoded><![CDATA[<p>I know you are probably itching to get stuck into the iPhone programming environment, but there are a few things you HAVE to learn first. One of them is Object Oriented Programming. The reason I am jumping right into this is that it is the main feature of Objective-C and a very powerful set of tools which you will need to understand if you want to create iPhone apps.</p>
<p>Let&#8217;s start by creating a new project in XCode. Fire up XCode and follow these steps:</p>
<ol>
<li>In XCode, click File &gt; New Project</li>
<li>Choose Command Line Utility &gt; Foundation Tool</li>
<li>Name the project &#8220;Objects Intro&#8221; and save it.</li>
</ol>
<p>In the project window, click the Source folder in the left-hand pane to view your source files. You should have one called &#8220;Objects Intro.m&#8221; and one called &#8220;Objects Intro_Prefix.pch&#8221; (which you can ignore for now.)</p>
<p>Object oriented programming languages are based around the use of <strong><em>objects</em></strong>. Objects can represent real life objects (like a chair or a car), or can be more abstract. Objects can hold variables, change variables and pass information between each other. This makes the development of complex applications much more simple. You will understand them more as we continue. Let&#8217;s make an object right now!<br />
 </p>
<p><span id="more-59"></span></p>
<p><br />
 </p>
<ol>
<li>In your project, click File &gt; New File</li>
<li>Click Cocoa in the left pane and select Objective-C class from the right pane. Click the Next button to continue.</li>
<li>In the next window, name your file: &#8220;Television.m&#8221; (without quotes) and make sure &#8220;Also create Television.h&#8221; <em><strong>is</strong></em> checked.</li>
<li>Click the finish button.</li>
</ol>
<p>Great! You should have two more files in your source folder now: &#8220;Television.m&#8221; and &#8220;Television.h&#8221;. We just created a Television object right? Wrong. What we have created is a Television <em><strong>Class. </strong><span style="font-style: normal;">A class is a collection of variables and methods that all work together. Methods are instructions to the computer to do something. In the previous tutorials, we created the Hello World method which told the computer to print some text and add some numbers together. However, that method wasn&#8217;t really part of a class.</span></em></p>
<p>In object oriented programming, objects are instances of classes. What we will do next is create the Television class that we can use to create a Television object. Why did we create two new files? Well the &#8216;.h&#8217; header file (or interface file) is basically a plan of how the class will look. The &#8216;.m&#8217; method file (or implementation file) is where most of our code will go. Imagine the interface file as the outline of a drawing and the implementation file as the details and colors of the drawing. Let&#8217;s go ahead and fill these files out &#8211; starting with the interface file:</p>
<p>Double click &#8220;Television.h&#8221; to open it for editing.</p>
<p>Edit the file to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Cocoa/Cocoa.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> Television <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> watch;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> turnOff;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Ok, save the file and let&#8217;s have a look at what we did.<br />
First, we used @interface to tell the compiler what kind of file we were creating. Then we told it the name of the class is Television. We can ignore <code>: NSObject</code> for now. Next, we created two methods. One called &#8220;watch&#8221; and one called &#8220;turnOff&#8221;. (void) means no values are returned from the method. We will learn about returning values later. @end ends the interface file.</p>
<p>Did you notice that &#8220;watch&#8221; and &#8220;turnOff&#8221; are things we would typically do to a real-life television? What else could you do? Have a think. We could have created methods for everything that we do to a TV, but to keep it simple I chose just to use watch and turn off for now.<br />
Now that we have created a plan for the Television class, we need to tell it what to do! Close Television.h and open Television.m.<br />
Now edit Television.m to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;Television.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> Television
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> watch <span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;You are watching the TV&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> turnOff <span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;The TV is now off.&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Let&#8217;s have a look at what we did. We used the #import function to import our Television.h file. Then we started the implementation file with @implementation Television. Do you remember the two methods we created in the interface file? Well in the implementation file we are telling them what to do! First we tell the &#8220;watch&#8221; method to print out that we are watching the TV. Next, we tell the turnOff method to print out a message confirming that the TV is off.</p>
<p>Great! Now our TV class is ready to be made into an object so we can use it! Save and close Television.m and open &#8220;Objects Intro.m&#8221;. You may notice that this file is identical to the Hello World file from the first tutorials. Remove the <code>// insert code here</code> and <code>NSLog(@"Hello, World!");</code> lines and add the following line in their place:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">Television <span style="color: #002200;">*</span>myTV <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Television alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>You just created a Television object! An object is an instance of a class. We called our Television object &#8220;myTV&#8221;. <code>[Television alloc] init];</code> This part of the line allocates some memory to store the object in and initializes it. Don&#8217;t worry too much about this yet. Now we have a Television object ready to use, let&#8217;s do something with it! But what can we do? Well, we have already defined what it can do with the watch and turnOff methods. Let&#8217;s watch it first! Add the following lines below the last one we typed:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>myTV watch<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>myTV release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Add the following line at the top, under the first import statement:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;Television.h&quot;</span></pre></div></div>

<p>Always remember to import the header files of the classes you use. Now, save and run the program! Remember to open the console by clicking Run &gt; Console.<br />
If all went well, your program should have printed: &#8220;You are watching the TV&#8221;. Let&#8217;s look at that code we just wrote. <strong>[myTV watch];</strong> called the watch method from your TV object and ran the code in that method! The second line: <strong>[myTV release];</strong> calls a method that we didn&#8217;t create. We will learn about this later &#8211; but for now you just need to know that release clears that object from memory. You must always clear anything you use from memory when you are finished with it.</p>
<p>Why don&#8217;t we test the other method now? Change <strong>[myTV watch];</strong> to <strong>[myTV turnOff];</strong><br />
If that method worked, it should have printed &#8220;The TV is now off.&#8221; Great! If you had left [myTV watch]; and added [myTV turnOff]; both lines of text would have been printed to the console.</p>
<p>So what did we do today? We created a class called Television and gave it two methods. Then we created a Television object (or instance of the Television class) and called the methods we created. Then using release, we removed the Television object from memory.<br />
Go through each file we created and add some comments explaining what is happening.</p>
<p>In the <a href="http://www.developingforiphone.com/2009/04/tutorial-2-2-properties-and-accessor-methods/">next tutorial</a>, we will be giving the Television class some properties, so remember to save your project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developingforiphone.com/2009/04/tutorial-2-1-introduction-to-object-oriented-programming/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
