Junior — Senior
Find defects in Swift code
livecode
Task condition
The task requires analyzing the provided Swift code snippet and identifying potential issues related to memory management and object lifecycle. Pay attention to the use of unowned and long delays on the main thread.
class Service {
func fetchData(completion: @escaping (String) -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + 20.0) {
completion("hello world")
}
}
}
class ViewController: UIViewController {
let dataService = Service()
let outputLabel = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
dataService.fetchData { [unowned self] (result) in
self.outputLabel.text = result
}
}
}