Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Object-Oriented Swift Properties Computed Properties

Jason Tzannes
Jason Tzannes
1,194 Points

What am I doing wrong?

What am I doing wrong other than naming a variable x? I get no output and have no idea what is wrong.

Temperature.swift
class Temperature {
    var celsius: Float 
    var x: Float {
      return (celsius * 1.8) + 32
    }
    init(celsius: Float) {
    self.celsius = celsius
    }
}

let fahrenheit = Temperature(celsius: 0.0)
fahrenheit.x
Grady Newman
Grady Newman
4,729 Points

Hi Jason,

I just copied your code into a playground and am showing 32 as the return from the Temperature class. There should not be any output in your console output in your assistant editor, as you are calling the println() or other similar function.

1 Answer

'''html<p> Hey jason, in the challenge they want you to name the computed property as "fahrenheit" and not "x". Despite the fact that your code is correct, the computer will let you go on if you only follow the instructions. This is how your code should look:class Temperature { var celsius: Float var x: Float { return (celsius * 1.8) + 32 } }</p>'''