Skip to content

Instantly share code, notes, and snippets.

@Plnda
Created May 23, 2020 22:13
Show Gist options
  • Save Plnda/dbefe027513ca83d96b951abc3f156d9 to your computer and use it in GitHub Desktop.
Save Plnda/dbefe027513ca83d96b951abc3f156d9 to your computer and use it in GitHub Desktop.
import UIKit
protocol WorkProtocol: class {
func work()
}
class ViewModel {
weak var delegate: WorkProtocol?
}
struct Bar {
let name: String = "test"
}
struct Foo {
let bar: Bar
}
class ViewController: UIViewController {
@Injected var viewModel: ViewModel
@Injected var foo: Foo
override func viewDidLoad() {
super.viewDidLoad()
print(foo.bar.name)
viewModel.delegate = self
// Call implementation
viewModel.delegate?.work()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
present(ViewController2(), animated: true, completion: nil)
}
}
extension ViewController: WorkProtocol {
func work() {
print("Im working!")
}
}
class ViewController2: UIViewController {
@Injected var viewModel: ViewModel
override func viewDidLoad() {
super.viewDidLoad()
viewModel.delegate?.work()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment