O'Reilly logo

iOS Programming: The Big Nerd Ranch Guide by Aaron Hillegass, Christian Keur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing the Temperature Conversion

With the basics of the interface wired up, let’s implement the conversion from Fahrenheit to Celsius. You are going to store the current Fahrenheit value and compute the Celsius value whenever the text field changes.

In ConversionViewController.swift, add a property for the Fahrenheit value. This will be an optional double (a Double?).

@​I​B​O​u​t​l​e​t​ ​v​a​r​ ​c​e​l​s​i​u​s​L​a​b​e​l​:​ ​U​I​L​a​b​e​l​!​

v​a​r​ ​f​a​h​r​e​n​h​e​i​t​V​a​l​u​e​:​ ​D​o​u​b​l​e​?

The reason this property is optional is because the user might not have typed in a number, similar to the empty string issue you fixed earlier.

Now add a computed property for the Celsius value. This value will be computed based ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required