Created
August 18, 2022 14:42
-
-
Save sebjvidal/c10ba260fb55dedfab09e538b7444a78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// task-test | |
// | |
// Created by Seb Vidal on 18/08/2022. | |
// | |
import UIKit | |
class FirstViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
@IBAction func buttonTapped(_ sender: Any) { | |
let vc = SecondViewController() | |
navigationController?.pushViewController(vc, animated: true) | |
vc.performTask() | |
} | |
} | |
class SecondViewController: UIViewController { | |
let viewModel = ViewModel() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.backgroundColor = .white | |
} | |
func performTask() { | |
Task { | |
await viewModel.fetchData(viewController: self) | |
} | |
} | |
func printMessage() { | |
print("Here") | |
} | |
} | |
class ViewModel { | |
init() { | |
print("init()") | |
} | |
func fetchData(viewController: SecondViewController) async { | |
DispatchQueue.main.asyncAfter(deadline: .now() + 10) { | |
viewController.printMessage() | |
} | |
} | |
deinit { | |
print("deinit") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment