<?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>MacOSCoders &#187; Free iPhone SDK</title>
	<atom:link href="http://www.macoscoders.com/tag/free-iphone-sdk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.macoscoders.com</link>
	<description>My blog to talk on iPhone, Mac OS, Adobe Flex, AIR...</description>
	<lastBuildDate>Thu, 06 Oct 2011 11:09:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Do you know how to build your own iPhone app?</title>
		<link>http://www.macoscoders.com/2009/01/01/do-you-know-how-to-build-your-own-iphone-app/</link>
		<comments>http://www.macoscoders.com/2009/01/01/do-you-know-how-to-build-your-own-iphone-app/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 18:13:00 +0000</pubDate>
		<dc:creator>Anish Kumar</dc:creator>
				<category><![CDATA[iPhone Applications]]></category>
		<category><![CDATA[iPhone Development]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[build iPhone app]]></category>
		<category><![CDATA[Free iPhone SDK]]></category>
		<category><![CDATA[mobile software gold rush]]></category>

		<guid isPermaLink="false">http://www.macoscoders.com/?p=17</guid>
		<description><![CDATA[
The iPhone SDK (software development kit) is free to download atwww.apple.com/developer, but only for Mac OS X. It&#8217;s based on the same Xcode development suite used to develop many Mac OS X apps, which provides a versatile environment for writing the Objective-C code that underpins iPhone software. It&#8217;s complemented by companion tools, such as Instruments, [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>The iPhone SDK (software development kit) is free to download at<a href="http://www.apple.com/developer">www.apple.com/developer</a>, but only for Mac OS X. It&#8217;s based on the same Xcode development suite used to develop many Mac OS X apps, which provides a versatile environment for writing the Objective-C code that underpins iPhone software. It&#8217;s complemented by companion tools, such as Instruments, that enable performance analysis and drag-and-drop interface building.</p>
<p><span id="more-17"></span>Here, we&#8217;ll use the iPhone SDK to code and build an interface for a restaurant gratuity calculator called TippedOff. The software enables you to enter the amount of a party&#8217;s bill with an on-screen keyboard, then adjust touch-operated sliders to set the number of people in the dining party and the proportion of the bill that decides the tip. The tip total updates automatically as you adjust these controls.</p>
<p>Getting started</p>
<p>In Xcode, select &#8216;File | New Project&#8217;. In the dialog that appears, click the &#8216;iPhone OS&#8217; pane in the left-hand list and choose &#8216;Window-Based Application&#8217; from the selection of application templates. Name this new project &#8216;TippedOff&#8217;.</p>
<p>In the main window that opens, select &#8216;TippedOff&#8217; in the left-hand list and then highlight &#8216;TippedOffAppDelegate.h&#8217; in the file list. This document lists the variables, interface functions and other components. At present, it contains a single controller, which is automatically named after the project name you entered – in this case, &#8216;TippedOffAppDelegate&#8217;. Remove the text between the curly brackets and enter the following in its place:<br />
float bill;<br />
float people;<br />
float tip;<br />
float split;<br />
IBOutlet UIWindow *window;<br />
IBOutlet UITextField *bill_enter;<br />
IBOutlet UILabel *bill_label,*people_label, *tip_label, *split_ label, *split_result;<br />
IBOutlet UISlider *people_slider, *tip_slider;</p>
<p>Note the semicolon ending each line. The first block defines our four variables – bill, people, tip and split – as floating-point numbers. The second sets up a series of interface elements, which are defined through the UI descriptions. The &#8216;IBOutlet&#8217; tag defines the elements as usable within Xcode&#8217;s companion program, Interface Builder.</p>
<p>Next, you&#8217;ll set property declarations to store the current status of each interface element. Delete the existing line that starts &#8216;@property&#8217; and replace it with a copy of the four current &#8216;IBOutlet&#8217; lines, pasting them below the AppDelegate curly brackets. On each line, exchange &#8216;IBOutlet&#8217; with &#8216;@property (nonatomic, retain)&#8217;, keeping the element names that follow.</p>
<p>The first line, for example, should read &#8216;@ property (nonatomic, retain) UIWindow *window;&#8217;. This declaration has two components – &#8216;nonatomic&#8217; aids multithreading efficiency, while &#8216;retain&#8217; prevents the property value from being erased without your approval.</p>
<p>Finally, we name the three functions that the application uses as &#8216;peopleSlider&#8217;, &#8216;tipSlider&#8217; and &#8217;splitResult&#8217;. Below the four &#8216;@property lines&#8217;, enter:<br />
- (IBAction)peopleSlider:(id)sender;<br />
- (IBAction)tipSlider:(id)sender;<br />
- (IBAction)splitResult:(id)sender;</p>
<p>Again, &#8216;IBAction&#8217; is a cue for Interface Builder, while the sender parameter identifies the source of a piece of data. Finally, as a separate line, enter the following:<br />
- (void)calculate;</p>
<p>This declaration of the &#8216;calculate&#8217; function is needed here, even though it&#8217;s undefined, because later functions invoke &#8216;calculate&#8217; as part of their operation.</p>
<p>Building the application</p>
<p>Now we&#8217;ll start to build the app&#8217;s mechanics. Begin by copying the four &#8216;@property&#8217; lines, and then switch to the document &#8216;TippedOffAppDelegate.m&#8217;.</p>
<p>Delete the line that opens with &#8216;@synthesize&#8217; and paste the four &#8216;@property&#8217; lines into the space, replacing &#8216;@property (nonatomic, retain)&#8217; with &#8216;@synthesize&#8217;. Next, remove the UI describers and the asterisks preceding each function. The &#8216;@synthesize&#8217; function here is an instruction for your software compiling program.</p>
<p>Several functions that handle application start-up and shut-down tasks are already set up. Any further functions are entered between them and &#8216;@end&#8217; line. The first section of code initialises the values of a few of the variables:<br />
- init</p>
<p>With the various functions defined as code, you can now assemble the application itself with the SDK&#8217;s graphical Interface Builder.</p>
<p>Adding some control</p>
<p>Double-click &#8216;MainWindow.xib&#8217; in the TippedOff file list to open a blank Interface window and a separate window holding objects to link to your interface parts.</p>
<p>Select &#8216;Tools | Library&#8217; to open up a list of objects that you can drag onto the Interface window. Start with a Label object in the top-left corner and a Text Field object in the top-right. Placement guidelines appear as you move objects around, enabling you to line up components easily.</p>
<p>Below these two objects, add two pairs of Label and Slider objects. Next, add two more Label objects in the bottom-left and bottom-right corners. Stretch the Slider objects so that they go across the screen&#8217;s width. Finally, adjust the bottom-right Label&#8217;s Layout Alignment to &#8216;right&#8217; to make it look a bit neater.</p>
<p>To change the text of the Labels, select &#8216;Tools | Attributes Inspector&#8217;. Then click on each Label in turn and change its &#8216;Text&#8217; value. From the top, rename the Labels as &#8216;Bill&#8217;, &#8216;2 people&#8217; and &#8216;15.0% tip&#8217;. Rename the bottom two Labels as &#8216;Split&#8217; and &#8216;0.00&#8242;. Some Labels will change values as the controls are adjusted, so what you&#8217;ve entered here represents the defaults that a user will see when the application is launched.</p>
<p>Next, you&#8217;ll link the interface parts to controllers so that the user&#8217;s adjustments to controls can affect the variables that you&#8217;ve established. Hold down [CTRL] then click-and-drag from the TippedOffAppDelegate object onto the Bill Label. From the pop-up menu that appears, select the &#8216;bill_label&#8217; Outlet.</p>
<p>Similarly, link the &#8216;people_label&#8217; Outlet to the &#8216;2 people&#8217; Label, &#8216;tip_label&#8217; to the &#8216;15.0% tip&#8217; Label, &#8217;split_label&#8217; to the &#8216;Split&#8217; Label and &#8217;split_ result&#8217; to the &#8216;0.00&#8242; Label.</p>
<p>Now hold down [CTRL] and once again click-and-drag from TippedOffAppDelegate to the Text Field object and link &#8216;bill_ enter&#8217;. Then link &#8216;people_slider&#8217; to the higher Slider object and &#8216;tip_slider&#8217; to the lower Slider.</p>
<p>You also need to link some Outlets in the opposite direction. Hold [CTRL], then click-and-drag from the Text Field object to TippedOffAppDelegate and select &#8216;delegate&#8217;. Similarly, link up peopleSlider and tipSlider to the higher and lower Sliders.</p>
<p>The final operations to complete in Interface Builder define the controls&#8217; behaviour more tightly. First, select the Text Field object. In the Attributes Inspector&#8217;s Text field, enter &#8216;0.00&#8242; as the default value, then change its Alignment to centred. Make sure that &#8216;Clear When Editing Begins&#8217; is ticked. Under Text Input Traits, set Keyboard Type to &#8216;Numbers &amp; Punctuation&#8217; so the user doesn&#8217;t have to switch over from the default keyboard. Change Return Key to &#8216;Done&#8217; and tick &#8216;Auto-enable Return Key&#8217;.</p>
<p>Now select the higher Slider object, which sets the number of people in the dining group. In Attributes, set Minimum to &#8216;2&#8242; (you don&#8217;t need to use the app if you&#8217;re eating alone&#8230;) and Maximum to &#8216;20&#8242;. Set Initial to &#8216;2&#8242; as well: this matches the default Label for this Slider that you created earlier. For the lower Slider, which is used to set the tip percentage, set Minimum to &#8216;0&#8242; and Maximum to &#8216;25&#8242;, then set Initial to &#8216;15&#8242; – again matching the default Label object you&#8217;ve defined for that Slider.</p>
<p>Your tip calculator is now ready to use. To try it out, return to Xcode and press &#8216;Build and Go&#8217; in the toolbar. Xcode compiles the code and bundles it into an application, triggering iPhone Simulator to present the result. You can use the app as you would on an iPhone, dragging sliders and entering the bill total in the top-right text field.</p>
<p>There&#8217;s a glut of such tools on the App Store, which provides a great opportunity to study how different programmers tackled the challenge of making a gratuity calculator. Why not see if you can come up with your own take on the app?</p>
<p>All the very best.</p>
</div>
<div id="wherego_related"><h3>Readers who viewed this page, also viewed:</h3><ul><li><a href="http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/" rel="bookmark" class="wherego_title">iPhone Apple Push Notification Service (APNS)</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/where-did-they-go-from-here/">Where did they go from here?</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.macoscoders.com/2009/01/01/do-you-know-how-to-build-your-own-iphone-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
array(0) {
}

