Skip to content

Instantly share code, notes, and snippets.

@sebjvidal
Created August 18, 2022 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebjvidal/c10ba260fb55dedfab09e538b7444a78 to your computer and use it in GitHub Desktop.
Save sebjvidal/c10ba260fb55dedfab09e538b7444a78 to your computer and use it in GitHub Desktop.
//
// 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