Sobes.tech
Junior — Senior

Identify errors in the provided Swift fragment

livecode

Task condition

In the example of the controller class below, there are several potential issues related to the use of optional properties and closures. Find and describe them.

class SomeViewController: UIViewController {
    private var titleLabel: UILabel!

    func printText(text: String) {
        Logging.log(text)
        titleLabel = createLabelAndConfigure()
    }

    func createLabelAndConfigure() -> UILabel {
        // assume this method is implemented
    }

    func performAction() {
        let service = SomeNetworkService()
        service.downloadObject { text in
            self.printText(text: text)
            self.titleLabel.text = text
        }
    }
}