Skip to content

Instantly share code, notes, and snippets.

@agiokas
Created March 23, 2021 22:04
Show Gist options
  • Select an option

  • Save agiokas/3c347435a5c931d21f0921d42c09ed4f to your computer and use it in GitHub Desktop.

Select an option

Save agiokas/3c347435a5c931d21f0921d42c09ed4f to your computer and use it in GitHub Desktop.
//
// Created by Apostolos Giokas on 23.03.21.
//
final class MyViewControllerFactory: ViewCοntrollerFactory {
override init() {
super.init()
register(vm: Data1.self) { UIViewController1(data: $0) }
register(vm: Data2.self) { UIViewController2(data: $0) }
}
}
struct Data1 {
let title: String
}
struct Data2 {
let color: UIColor
}
final class UIViewController1: UIViewController {
let label = UILabel(frame: .init(x: 30, y: 40, width: 300, height: 40))
init(data: Data1) {
super.init(nibName: nil, bundle: nil)
label.text = data.title
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
view.addSubview(label)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
final class UIViewController2: UIViewController {
init(data: Data2) {
super.init(nibName: nil, bundle: nil)
self.view.backgroundColor = data.color
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment