<?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>cnicollonline &#187; Objective-C</title>
	<atom:link href="http://cnicollonline.com/category/programming/objective-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://cnicollonline.com</link>
	<description>&#34;I was just guessing at numbers and figures, pulling the puzzles apart&#34;</description>
	<lastBuildDate>Mon, 23 Aug 2010 19:16:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Objective-C images</title>
		<link>http://cnicollonline.com/programming/objective-c-images/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://cnicollonline.com/programming/objective-c-images/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 18:46:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://cnicollonline.com/?p=261</guid>
		<description><![CDATA[When programming in any language I find that there are always several things that no matter how hard I try to remember will never stick. One thing as of late has been using images within objective-c and iPhone&#160;development. So many&#160;ways! There are several ways to get images onto your display. The two I find I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>When programming in any language I find that there are always several things that no matter how hard I try to remember will never stick. One thing as of late has been using images within objective-c and iPhone&nbsp;development.</p>
<p><span id="more-261"></span></p>
<h3>So many&nbsp;ways!</h3>
<p>There are several ways to get images onto your display. The two I find I&#8217;m using the most are calling an image from the web, and using an image from your resource directory. Below are two snippets that I find useful to have within your snippet&nbsp;collection.</p>
<h3>Snippet 1: Getting an image from the&nbsp;web</h3>
<ul>
<li>The image link I&#8217;ll be using in the first example is:&nbsp;<a href="http://goo.gl/QL0z">http://farm5.static.flickr.com/4098/4911106000_9c3a16bb59.jpg</a></li>
</ul>
<pre class="brush: objc;">
// ----------------------- .h ------------------------
...
UIImageView *imgHolder;
...
@property(nonatomic, retain) IBOutlet UIImageView *imgHolder;

// ----------------------- .m ------------------------
// PART 1 - update url of path to the image
// PART 2 - update the variable reference to the UIImageView object
// -----------------------------------------------

// ===== PART 1 =====
NSString *imgURLpath = @&quot;http://farm5.static.flickr.com/4098/4911106000_9c3a16bb59.jpg&quot;;
UIImage *imgURL = [[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: imgURLpath]]] retain];

if (imgURL != nil) { // Image was loaded successfully.
	// ===== PART 2 =====
	[imgHolder setImage:imgURL];
	// ===== PART 2 =====
	[imgHolder setUserInteractionEnabled:NO];
	[imgURL release]; // Release the image now that we have a UIImageView that contains it.
}
</pre>
<h3>Snippet 2: Getting an image from the resource&nbsp;folder</h3>
<ul>
<li>The image I&#8217;ll be using&nbsp;is:</li>
<p>	<a href="http://www.flickr.com/photos/98682661@N00/4911106000/" title="08-20-10_11-19 by Cosizzle, on Flickr"><img src="http://farm5.static.flickr.com/4098/4911106000_9c3a16bb59.jpg" width="230" height="380" alt="08-20-10_11-19" /></a></p>
<li>The image above will need to be added to your applications resource folder. <em>Note: Don&#8217;t forget to check off &#8220;Copy items to destination group&#8217;s folder. Unless that&#8217;s not your style&#8221; <img src='http://cnicollonline.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></li>
</ul>
<pre class="brush: objc;">
	// ----------------------- .h ------------------------
	...
	UIImageView *imgHolder;
	...
	@property(nonatomic, retain) IBOutlet UIImageView *imgHolder;

	// ----------------------- .m ------------------------
	// PART 1 - create an image object
	// PART 2 - update the variable reference to the UIImageView object
	// -----------------------------------------------

	// ===== PART 1 =====
	// note: the image in use should be in your resource folder
	NSString *imgName = @&quot;4911106000_9c3a16bb59.jpg&quot;;
	UIImage *myImg = [UIImage imageNamed:imgName];

	if (myImg != nil) { // Image was loaded successfully.
		// ===== PART 2 =====
		[imgHolder setImage:myImg];
		// ===== PART 2 =====
		[imgHolder setUserInteractionEnabled:NO];
		[myImg release]; // Release the image now that we have a UIImageView that contains it.
	}
	</pre>
]]></content:encoded>
			<wfw:commentRss>http://cnicollonline.com/programming/objective-c-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UITableView Application Tutorial</title>
		<link>http://cnicollonline.com/programming/uitableview-application-tutorial/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://cnicollonline.com/programming/uitableview-application-tutorial/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 22:29:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://cnicollonline.com/?p=249</guid>
		<description><![CDATA[Learning Objective-C coupled with the Interface Builder, I found that using a UIImageHolder, or UITextLabel, or even the UIScrollBar came more and more simple each time I used them. I had my laptop with a full battery, a fresh piece of paper to scribble on and I was ready to tackle a Navigation-based&#160;Application. Now this [...]]]></description>
			<content:encoded><![CDATA[<p><!--<br />
- Wobjobjc]ORDPRESS TEMPLATE FOR CREATING OR POSTING TO MY BLOG.<br />
- COMMON TAGS TO&nbsp;NOTE:</p>
<p>-<br />
<h2>MAIN&nbsp;TITLE</h2>
<p>-<br />
<h3></h3>
<p>-<br />
<h4></h4>
<p>-
<ul>
<li>LIST&nbsp;ITEM</li>
</ul>
<p>-
<ol>
<li>ORDER LIST&nbsp;ITEM</li>
</ol>
<p>- adding a download link<br />
<a href="http://www.cnicollonline.com/wp-articles/PATH TO LINK" target="_self">click&nbsp;here</a></p>
<p>- adding an&nbsp;image</p>
<div class="tutorial_image"><img src="http://www.cnicollonline.com/wp-articles/PATH TO IMG/1.jpg" border="0" /></div>
<p>--></p>
<p>Learning Objective-C coupled with the Interface Builder, I found that using a UIImageHolder, or UITextLabel, or even the UIScrollBar came more and more simple each time I used them. I had my laptop with a full battery, a fresh piece of paper to scribble on and I was ready to tackle a Navigation-based&nbsp;Application.</p>
<p>Now this wasn&#8217;t a hard feat, but it wasn&#8217;t an one easy either. I feel I have a good foot in the door with this, but far from a &#8220;pro&#8221;&nbsp;status.</p>
<p><span id="more-249"></span></p>
<h2>Why so&nbsp;simple?</h2>
<p>I wanted to keep things simple here. The basis for this tutorial is to quickly show how to build a Navigation-based Application that does no more than load a view when clicking on a&nbsp;cell.</p>
<p>I&#8217;m not sure if this is the best way to do it, and in more complex projects this may not prove to be resourceful. However for getting started, for me this did the&nbsp;trick!</p>
<h3>Step&nbsp;1</h3>
<p>Go ahead and create a new Table View Application within&nbsp;xCode</p>
<div class="tutorial_image"><img src="http://farm3.static.flickr.com/2719/4409500308_48cd222162.jpg" border="0" /></div>
<h3>Step&nbsp;2</h3>
<p>Create a few controller classes for our views to work with. For this tutorial I created&nbsp;three.</p>
<ol>
<li>SubViewControllerOne</li>
<li>SubViewControllerTwo</li>
<li>SubViewControllerThree</li>
</ol>
<p><em>note: that you need both .m and .h&nbsp;files</em></p>
<p>Next create the nib, or view files to work along with the&nbsp;controllers</p>
<ol>
<li>SubViewOne.xib</li>
<li>SubViewTwo.xib</li>
<li>SubViewThree.xib</li>
</ol>
<p>I understand that at the time when creating a controller, you also have the option to create a nib file at the sime time. I choose not to do this because of how Xcode names it&#8217;s nibs. for example &#8220;SubViewControllerOne&#8221; controller would have a nib file called &#8220;SubViewControllerOne&#8221; which is fine, however because my controller contains the word &#8220;controller&#8221; that could lead to confusion down the road. It also doesnt stick the nib file in the Resource folder but rather the class folder. There is no right or wrong answer here, just whatever makes you sleep better at night I&nbsp;suppose.</p>
<p>By now your classes and resource folder should look like the&nbsp;following</p>
<div class="tutorial_image"><img src="http://farm3.static.flickr.com/2680/4408785065_78f7837d79_o.jpg" border="0" /></div>
<p><em>note: I subgrouped my sub view controllers. Again personal&nbsp;preference.</em></p>
<h3>Step&nbsp;3</h3>
<p>We need to link our nib files to their controllers, so open up each nib file and assign the <b>File Owner</b> to the correct&nbsp;controller</p>
<div class="tutorial_image"><img src="http://farm5.static.flickr.com/4067/4408771637_5f4dc82665.jpg" width="500" height="179" alt="03-02-10_19-32_UITableView_03" /></div>
<p> Then ctrl+click on the <b>File Owner</b> delegate and drag the blue line to the view - to link up the&nbsp;view.</p>
<div class="tutorial_image"><img src="http://farm3.static.flickr.com/2789/4409543602_c8cb84ef06.jpg" border="0" /></div>
<p>While we&#8217;re at it we might as well put a label on our view so we know that indeed the view is being&nbsp;loaded.</p>
<div class="tutorial_image"><img src="http://farm5.static.flickr.com/4070/4409558504_5003a7db66.jpg" border="0" /></div>
<h3>Step&nbsp;3</h3>
<p>Rinse and repeat step 2 for the other two nib&nbsp;files</p>
<h3>Step&nbsp;4</h3>
<p>Alright with everything linked up and ready to go, we can dive into some code! Most of, if not all the programming we&#8217;re going to be using will be within the <em>RootViewController</em> class. Go ahead and open&nbsp;<em>RootViewController.h</em></p>
<p>We&#8217;re not going to do a whole lot in here, however to load in and out different views, depending on the cell, I plan to store all this within an NSMutableArray that will hold a NSDictionary object. Let&#8217;s declare the NSMutable array within the <em>RootViewController.h</em>&nbsp;file.</p>
<p>Your <em>RootViewController.h</em> should now look like&nbsp;this</p>
<h4>RootViewController.h</h4>
<pre class="brush: objc;">
@interface RootViewController : UITableViewController {

	NSMutableArray *views;
}

@property(nonatomic, retain) IBOutlet NSMutableArray *views;

@end
</pre>
<p>Next head over to <em>RootViewController.m</em> and let&#8217;s add some code. First off it&#8217;s important we include all the view controllers we plan to use as well as synthesize the view&nbsp;object</p>
<pre class="brush: objc;">
#import &quot;RootViewController.h&quot;
#import &quot;SubViewControllerOne.h&quot;
#import &quot;SubViewControllerTwo.h&quot;
#import &quot;SubViewControllerThree.h&quot;

@implementation RootViewController
@synthesize views;

...
</pre>
<p>Next we call the
<pre class="brush: objc;">-(void) awakeFromNib {...}</pre>
<p> function and start adding our NSDictionary objects to the view. The NSDictionary will hold to&nbsp;properites:</p>
<ol>
<li><em>@title</em> - Title you see at the top of the&nbsp;view</li>
<li><em>@controller</em> - The controller&nbsp;object</li>
</ol>
<pre class="brush: objc;">
-(void) awakeFromNib
{
	views = [[NSMutableArray alloobjc] init];

	// ============================== CELL 1 ==============================

	//init the view
	SubViewControllerOne *viewOne = [[SubViewControllerOne alloobjc] init];

	// value - key pairing
	[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
					  @&quot;cell 1&quot;,	@&quot;title&quot;,
					  viewOne,		@&quot;controller&quot;,
					  nil]];

	[viewOne release];

	// ============================== CELL 2 ==============================

	//init the view
	SubViewControllerTwo *viewTwo = [[SubViewControllerTwo alloobjc] init];

	// value - key pairing
	[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
					  @&quot;cell 2&quot;,	@&quot;title&quot;,
					  viewTwo,		@&quot;controller&quot;,
					  nil]];

	[viewTwo release];

	// ============================== CELL 3 ==============================

	//init the view
	SubViewControllerThree *viewThree = [[SubViewControllerThree alloobjc] init];

	// value - key pairing
	[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
					  @&quot;cell 3&quot;,	@&quot;title&quot;,
					  viewThree,	@&quot;controller&quot;,
					  nil]];

	[viewThree release];
}
</pre>
<h3>Step&nbsp;4</h3>
<p>Ok cool, we&#8217;re getting somewhere. We&#8217;ve now loaded our views array with Objects that will load a view as well as create a title, next we have to modify how many rows there will be, what the title is, and what view is&nbsp;loaded.</p>
<p>First start off by stating how many rows are within the table. Locate this function and modify it. All that&#8217;s going on is that you&#8217;re specifying how many objects are in your view array, which should equal the amount of rows&nbsp;needed.</p>
<pre class="brush: objc;">
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    [views count];
}
</pre>
<p>Next let&#8217;s get the titles in place. Find this function and modify&nbsp;it</p>
<pre class="brush: objc;">
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @&quot;Cell&quot;;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloobjc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

	// Configure the cell.
	cell.textLabel.text = [[views objectAtIndex:indexPath.row] objectForKey:@&quot;title&quot;]; 

    return cell;
}
</pre>
<p>And finally, let&#8217;s load in the appropriate view depending on the cell being clicked. Modify this&nbsp;function&#8217;</p>
<pre class="brush: objc;">
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Navigation logic may go here -- for example, create and push another view controller.
	// AnotherViewController *anotherViewController = [[AnotherViewController alloobjc] initWithNibName:@&quot;AnotherView&quot; bundle:nil];
	// [self.navigationController pushViewController:anotherViewController animated:YES];
	// [anotherViewController release];

	UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@&quot;controller&quot;];
	[self.navigationController pushViewController:targetViewController animated:YES];
}
</pre>
<h3>Step&nbsp;5</h3>
<p>We&#8217;re almost there! Just one (well 3) minor things. It would be nice for the user to get back home. So let&#8217;s create the functionality for that. You will need to do this in all 3 of your viewController&nbsp;classes.</p>
<p>Open up <em>SubViewControllerOne.m</em> and replace the function as well as create the other function seen&nbsp;below</p>
<pre class="brush: objc;">
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloobjc] initWithTitle:
	    @&quot;HOME&quot; style:UIBarButtonItemStylePlain
	    target:self
		action:@selector(goHome:)] autorelease]; //auto released memory

    [super viewDidLoad];
}

-(void)goHome:(id)sender{
	NSLog(@&quot;Go Home!&quot;);
	[self.navigationController popToRootViewControllerAnimated:YES];
}
</pre>
<p><em>Be sure to do this in all three of your&nbsp;ViewControllers</p>
<h2>Closing&nbsp;thoughts</h2>
<p>By now you should be ready to compile and build, hopefully everything should be up and running. If it&#8217;s not I&#8217;ve attached my file&nbsp;<a href="http://www.cnicollonline.com/wp-articles/03-02-10_19-32_UITableView/TableViewApplication.zip" target="_self">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cnicollonline.com/programming/uitableview-application-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Templates within xCode</title>
		<link>http://cnicollonline.com/programming/custom-templates-within-xcode/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://cnicollonline.com/programming/custom-templates-within-xcode/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 19:02:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://cnicollonline.com/?p=223</guid>
		<description><![CDATA[While sitting in my Objective-C class learning about the Tab Bar Application and it&#8217;s uses our teacher brought up a point in that Apple&#8217;s pre-made Tab Bar Application, is good&#8230; but not great. The problem is that it starts you up with two views (which is good), However the first view is the main controller. [...]]]></description>
			<content:encoded><![CDATA[<p><!--<br />
- WORDPRESS TEMPLATE FOR CREATING OR POSTING TO MY BLOG.<br />
- COMMON TAGS TO&nbsp;NOTE:</p>
<p>-<br />
<h2>MAIN&nbsp;TITLE</h2>
<p>-<br />
<h3></h3>
<p>-<br />
<h4></h4>
<p>-
<ul>
<li>LIST&nbsp;ITEM</li>
</ul>
<p>-
<ol>
<li>ORDER LIST&nbsp;ITEM</li>
</ol>
<p>- adding a download link<br />
<a href="http://www.cnicollonline.com/wp-articles/PATH TO LINK" target="_self">click&nbsp;here</a></p>
<p>- adding an&nbsp;image</p>
<div class="tutorial_image"><img src="http://www.cnicollonline.com/wp-articles/PATH TO IMG/1.jpg" border="0" /></div>
<p>--></p>
<p>While sitting in my Objective-C class learning about the Tab Bar Application and it&#8217;s uses our teacher brought up a point in that Apple&#8217;s pre-made Tab Bar Application, is good&#8230; but not great. The problem is that it starts you up with two views (which is good), However the first view is the main controller. The second view has it&#8217;s own controller assigned to it. After a little research and a quick modification to the Tab Bar Application I was able to create my own template that I now use for Tab Bar&nbsp;projects.</p>
<div class="tutorial_image"><img src="http://farm3.static.flickr.com/2772/4348683609_dda7901693_o.jpg" border="0" /></div>
<p><span id="more-223"></span></p>
<p>To start off, and as my teacher suggested it&#8217;s probably best for the project to have 3 different&nbsp;controllers.</p>
<ol>
<li>MainController which connects the NIB MainWindow.xib
<ul>
<li>This will be the main view in which links the other view&#8217;s to the tab&nbsp;bar</li>
</ul>
</li>
<li>FirstViewController which connects the NIB&nbsp;FirstView.xib</li>
<li>SecondViewController which connects the NIB&nbsp;SecondView.xib</li>
</ol>
<p>To create a custom&nbsp;template:</p>
<p><strong>NOTE:</strong> It&#8217;s probably a good idea to quit xCode.app before going&nbsp;ahead!</p>
<ol>
<li>Download the template&nbsp;<a title="Template Download" href="http://www.cnicollonline.com/wp-articles/02-11-10_00-00_customTemplate_xCode/Tab Bar Application [Modded].zip">here</a></li>
<li>Within the Finder open: <strong>~/Library/Application&nbsp;Support/Developer/Shared/Xcode/</strong></li>
<li>If a folder doesn&#8217;t exist, create a new folder called &#8220;Project Templates&#8221; within that directory
<ul>
<li>You should now have a directory like &#8220;<strong>~/Library/Application Support/Developer/Shared/Xcode/Project&nbsp;Templates/</strong>&#8221;</li>
</ul>
</li>
<li>Create a new &#8220;Category&#8221; (new folder). In my case I called in &#8220;Custom Templates&#8221; within /Project&nbsp;Templates/</li>
<li>Drag the &#8220;Tab Bar Application [Modded]&#8221; folder within your newly made Category&nbsp;folder</li>
<li>Launch xCode and it should all be there and&nbsp;working!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://cnicollonline.com/programming/custom-templates-within-xcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Start to Objective-C</title>
		<link>http://cnicollonline.com/programming/a-start-to-objective-c/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://cnicollonline.com/programming/a-start-to-objective-c/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 20:09:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://cnicollonline.com/?p=217</guid>
		<description><![CDATA[It&#8217;s been a short time since I&#8217;ve gotten anything written, this was due to work being busy, a few small side projects, school projects and exams, summer starting and well - a new love. This love however can be bought with money and it involves selling a bit of your&#160;soul. After waiting a year I [...]]]></description>
			<content:encoded><![CDATA[<p><!--<br />
- WORDPRESS TEMPLATE FOR CREATING OR POSTING TO MY BLOG.<br />
- COMMON TAGS TO&nbsp;NOTE:</p>
<p>-<br />
<h2>MAIN&nbsp;TITLE</h2>
<p>-<br />
<h3></h3>
<p>-<br />
<h4></h4>
<p>-
<ul>
<li>LIST&nbsp;ITEM</li>
</ul>
<p>-
<ol>
<li>ORDER LIST&nbsp;ITEM</li>
</ol>
<p>- adding a download link<br />
<a href="http://www.cnicollonline.com/wp-articles/PATH TO LINK" target="_self">click&nbsp;here</a></p>
<p>- adding an&nbsp;image</p>
<div class="tutorial_image"><img src="http://www.cnicollonline.com/wp-articles/PATH TO IMG/1.jpg" border="0" /></div>
<p>--></p>
<p>It&#8217;s been a short time since I&#8217;ve gotten anything written, this was due to work being busy, a few small side projects, school projects and exams, summer starting and well - a new love. This love however can be bought with money and it involves selling a bit of your&nbsp;soul.</p>
<p>After waiting a year I was finally able to get a iPhone. 3Gs at that! This quickly pulled my interest away from my every day languages and set me on a course to learn&nbsp;Objective-C.</p>
<p><span id="more-217"></span></p>
<h3>Back to the&nbsp;start</h3>
<p>Through a <a href="http://www.iphonesdkarticles.com/2008/07/first-iphone-application.html" target="_blank">tutorial</a> a while back I was able to build a &#8216;helloworld&#8217; application that ran! It was very exciting and it brought me back to why I enjoy programming so much. However coming from a PHP and Java background (very little C-anything) it was pretty deep water at times. There were odd function calls, and the instance variables were hard identify. It was clear that all elements of an OOP language were there, just at the cost of an odd syntax&nbsp;layout.</p>
<p>Not to get overwhelmed by the complexity of the language I went out and picked up <a href="http://www.amazon.com/Programming-Objective-C-2-0-Developers-Library/dp/0321566157/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1246909328&#038;sr=8-1" target="_blank">Programming in Objective-C 2.0 (2nd Edition)</a>. I&#8217;m only on Chapter 3 but unknown tidbits are starting to make a little more sense, and I am now able to identify the common elements between Objective-C and other OOP&nbsp;languages.</p>
<h3>The&nbsp;Code</h3>
<p>This article isn&#8217;t a whole lot on the learning part, just a quick demo on a helloworld application written in PHP, Java and,&nbsp;Objective-C</p>
<h4>PHP</h4>
<pre class="brush: php;">
&lt;?php
$word1 = 'hello';
$word2 = 'world';

function $printText() {
	return $word1.' '.$word2
}

echo $printText();
?&gt;
</pre>
<h4>Java</h4>
<pre class="brush: java;">
package ocTest;

public class HelloWorld {
	private String word1;
	private String word2;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new HelloWorld();
	}

	private HelloWorld() {
		setWord1(&quot;hello&quot;);
		setWord2(&quot;world&quot;);

		System.out.println(printText());
	}

	/**
	 * @param word1 the word1 to set
	 */
	public void setWord1(String word1) {
		this.word1 = word1;
	}

	/**
	 * @param word2 the word2 to set
	 */
	public void setWord2(String word2) {
		this.word2 = word2;
	}

	private String printText() {
		return word1 + &quot; &quot; + word2;
	}

}
</pre>
<h4>Objective-C</h4>
<pre class="brush: cpp;">
#import &lt;Foundation/Foundation.h&gt;

// --- @interface ----
@interface TheString: NSObject
{
	char word1;
	char word2;
}

-(void) printText;
-(void) setWord1: (char) w1;
-(void) setWord2: (char) w2;

@end

// --- @implementation ---
@implementation TheString

-(void) printText
{
	NSLog(@&quot;%@ %@&quot;, word1, word2);
}

-(void) setWord1: (char) w1
{
	word1 = w1;
}

-(void) setWord2: (char) w2
{
	word2 = w2;
}

@end

// --- Main ---
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	TheString *myString;

	[myString setWord1: 'hello'];
	[myString setWord2: 'world'];

	[myString printText];
	[myString release];

    [pool drain];
    return 0;
}
</pre>
<h3>Conclusion</h3>
<p>I find it quite interesting that such a simple application such as &#8216;hello world&#8217; can become so complex. Of course I went a little overboard with the instance variables and the setters. More to come soon, hopefully something on the iPhone&nbsp;soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://cnicollonline.com/programming/a-start-to-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

