Saturday, December 29, 2012

iOS first App: Temperature Conversion

Apple's first app tutorial is excellent, but many times having more examples help, so here's my simple first app tutorial, a very simple temperature conversion application; It has one input, a text field for entering a temperature in Fahrenheit degrees, and a button, that will convert it to celsius and display it. Check the short demo video below.

If you prefer videos, here's a video walkthrough; if not, follow allong.

First, we create a new project, single-view application;let's call it Temperature Conversion
Then fill out the other project options as below (make sure you select use storyboard and use reference counting, and use Temp as class prefix, to make the class names the same as in this walkthrough; select iphone for device, to simplify; put whatever you prefer for the other values).

After you choose where to save your project, you should see the full xcode workspace, similar to the screenshot below (which has extra annotations :). Notice the list (or hierarchy) of files is to the left, in the middle there's an editor, wich changes depending on the file selected, and on the right there's a secondary editor, plus the object library at the bottom.

First, select the TempViewController.h file and modify the code so it looks like the screenshot below (the actual code is below the screenshot)

Then, select the storyboard, and, from the object library (bottom right, notice this is a list, and you can scroll) drag a text field,  a label and a button onto the storyboard.

Now, ctrl-click on the text field, to get its menu, and drag from the new referencing outlet to the Temp View Controller, and select fahrenheit, the only option (a line will appear when you drag, but doesn't appear in the screenshot)

Now do the same with the label
And finally join the touch up inside event in the button with the convertToCelsius method in the controller

And now we go to the TempViewController.m file to add the actual code; for easier understanding (not terribly useful now, but useful in larger programs), we first create a method for converting from fahrenheit to celsius, which I'm calling faren2celsius
And then the actual code for handling the button press; we access our properties with dot notation and using self to refer to ourselves, so self.fahrenheit is the text field, and self.celsius is the label; they both have a text property, of type NSString, and the NSString class has an intValue method that parses a string into an int.

Now press command-R or click on the run button, and you get your first iPhone app !

Finishing touches

  1. Go back to the storyboard, and add a couple of labels that say Fahrenheit and Celsius, next to each field.
  2. Change the title of the button to Convert to Celsius
  3. Change the text inside the label so it is blank, instead of saying 'label'.
Extending the program
  1. Change the declaration of celsius in TempViewController.h to be a textfield, and, on the storyboard, delete the label, and another textfield and link it to the view controller.
  2. Add another method in TempViewController.m (and declare it in TempViewController.m), called convertToFarenheit, that will convert from celsius (which is now a textfield) and put it into the fahrenheit field.
  3. Add another button to the storyboard, and link it to this method.
  4. Verify that you can convert back and forth between fahrenheit and celsius.


  1. You can find several different sorts of Temperature converter, so every one of which contains its own own intent. At the United States, the Fahrenheit scale is most commonly utilised (for example ) to record temperatures from the headlines headlines ). You are going to find it utilised if pharmacies, banks, etc.. . examine that the afternoon's fever on digital indications in your roads. It's a convenient extension for scientific query plus it's used across the globe. Other significant temperatures scale is currently Fahrenheit that's used chiefly in United States. The system for converting from Celsius to Fahrenheit is much more complex.I'm utilizing this fever converter and earn the maximum correct conversions immediately, depending on some fever scales. The worthiness at Fahrenheit might be gotten by multi ply Celsius worth by 1.8 then add 3 2. H2o freezing position are currently in 32 Fahrenheit. The very Optimal/optimally way to Have the conversion performed would be always to utilize an Internet fever converter When the temperatures drops exceeding 0 amounts, the water molecules have been losing rate, the fascination between these is slowly developing and they crystallize forming ice. We are all aware the drinking water volume is steadily currently rising after freezing. That is really since the hydrogen molecules have been exercising a fantastic allure which makes the drinking water molecules have to be ordered in a particular placement, which makes spaces between these, and also hence causing the quantity be higher compared to the amount of atoms would be the exact same.

  2. Other significant temperatures scale is Fahrenheit that's used mainly in United States. The formula for converting from Celsius to Fahrenheit is much more complex.I am utilizing this fever converter and gain the maximum precise conversions instantly, according to my temperature scales. The value at Fahrenheit could be gotten by multiply Celsius value by 1.8 and then add 3 2. Water freezing level is in 32 Fahrenheit. The very best way to get the conversion performed is to use an Internet You can find various kinds of temperature converter, so every one of which has its own own purpose. You'll find lots of temperatures scales Fahrenheit, Celsius and Kelvin scales. In the United States, the Fahrenheit scale is most often utilised (for example ) to report temperatures in the headlines ). Back in Europe, the Celsius scale is most commonly utilized. You will find it utilized if banks, pharmacies, etc. report the day's fever on digital indicators in your roads. But in science, the Kelvin scale is most often employed. It is a convenient scale for scientific inquiry plus it is used around the world. When the temperature drops approaching 0 amounts, the water molecules have been losing rate, the attraction between them is developing and they crystallize forming ice. We all know that the water volume is steadily rising if freezing. That is really since the hydrogen molecules are still exercising a excellent attraction making the water molecules to be arranged in a specific placement, leaving small spaces between these, and also hence causing the quantity to be higher while the number of molecules would be the same.