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 Intermediate Swift Properties Property Observers

Gabriel Walsh
Gabriel Walsh
21,531 Points

error: 'required' initializer 'init(coder:)' must be provided by subclass of 'UIViewController'

This passes the challenge but doesn't compile.

observer.swift
class TemperatureController: UIViewController {
    var temperature: Double {
        didSet {
            if temperature > 80.0 {
                view.backgroundColor = UIColor.red
            } else if temperature < 40.0 {
                view.backgroundColor = UIColor.blue
            } else {
                view.backgroundColor = UIColor.green
            }
        }
    }

        init(temperature: Double) {
            self.temperature = temperature
            super.init()
        }

        override func viewDidLoad() {
            super.viewDidLoad()
            view.backgroundColor = .white
        }
}

2 Answers

Jonathan Ruiz
Jonathan Ruiz
2,998 Points

Hi Gabriel do you mean it passed the challenge but doesn't compile in Xcode ? Did you import UIKIt in the Xcode playground ? you would need to to access the items like UIColor in that framework

Gabriel Walsh
Gabriel Walsh
21,531 Points

Jonathan -

Thanks so much for your answer. I did indeed import UIKit to a single playground.

Thanks!

Jonathan Ruiz
Jonathan Ruiz
2,998 Points

Hey Gabriel thats awesome ! I have had that issue before I wasn't sure but it sounded like that was the problem happy to help. Im still wrapping my head around this stuff to but I know that in order to access certain methods and code you have to use frameworks. Happy coding !