SimpleTemperatureConverter

Last Revision:
Version 1.2, 2012-06-05
Updated for Mac OS X 10.7
(Full Revision History)
Build Requirements:
Xcode 4.0 or later, Mac OS X v10.7 or later
Runtime Requirements:
Mac OS X v10.7 or later

An extremely simple application utilizing a simple model object which stores a temperature, allowing you to set or get the value using Celsius, Fahrenheit, or Kelvin scales. The model object is KVC and KVO compliant, which means you can bind to it and create UI without any code.

The Temperature class stores the temperature. The temperature is internally stored as celsius, but that is an implementation detail. The setCelsius: and celsius methods work on the instance variable, while the correspnding fahrenheit and kelvin methods call the celsius methods with the right conversion. The fahrenheit and kelvin values are declared to be dependent on celsius, which means any change in one will inform observers of any of these values.

The UI consists of three text fields bound to the three values, celsius, fahrenheit, and kelvin. The text fields have attached number formatters which ensure that the value generated by the text fields are NSNumbers. In addition, the formatters have appropriate minimum values specified. Thanks to this, we do not need to write validate methods in the Temperature class to check the class of the incoming value or validate the range.