|
7 | 7 | import UIKit |
8 | 8 |
|
9 | 9 | public class CodeBaseView<ViewModel>: UIView { |
10 | | - open var hierarchies: [HierarchyRelation] { [] } |
11 | | - |
12 | | - override init(frame: CGRect) { |
13 | | - super.init(frame: frame) |
14 | | - setupHierarchy() |
15 | | - setupConstraints() |
16 | | - } |
17 | | - |
18 | | - required init?(coder: NSCoder) { |
19 | | - fatalError("init(coder:) has not been implemented") |
20 | | - } |
21 | | - |
22 | | - private var viewModel: ViewModel? { |
23 | | - didSet { |
24 | | - configureView(viewModel) |
| 10 | + |
| 11 | + open var hierarchies: [HierarchyRelation] { [] } |
| 12 | + |
| 13 | + override init(frame: CGRect) { |
| 14 | + super.init(frame: frame) |
| 15 | + setup() |
| 16 | + } |
| 17 | + |
| 18 | + @available(*,unavailable) |
| 19 | + required init?(coder: NSCoder) { |
| 20 | + fatalError("init(coder:) has not been implemented") |
| 21 | + } |
| 22 | + |
| 23 | + private func setup() { |
| 24 | + setupHierarchy() |
| 25 | + setupConstraints() |
| 26 | + } |
| 27 | + |
| 28 | + private var viewModel: ViewModel? { |
| 29 | + didSet { |
| 30 | + configureView(viewModel) |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + public func setupViewModel(_ viewModel: ViewModel) { |
| 35 | + self.viewModel = viewModel |
25 | 36 | } |
26 | | - } |
27 | | - |
28 | | - public func setupViewModel(_ viewModel: ViewModel) { |
29 | | - self.viewModel = viewModel |
30 | | - } |
31 | | - |
32 | | - private func setupHierarchy() { |
33 | | - for relation in hierarchies { |
34 | | - for subview in relation.subviews { |
35 | | - if let stackView = relation.parentView as? UIStackView { |
36 | | - stackView.addArrangedSubview(subview) |
37 | | - } else { |
38 | | - relation.parentView.addSubview(subview) |
| 37 | + |
| 38 | + private func setupHierarchy() { |
| 39 | + for relation in hierarchies { |
| 40 | + for subview in relation.subviews { |
| 41 | + if let stackView = relation.parentView as? UIStackView { |
| 42 | + stackView.addArrangedSubview(subview) |
| 43 | + } else { |
| 44 | + relation.parentView.addSubview(subview) |
| 45 | + } |
| 46 | + } |
39 | 47 | } |
40 | | - } |
41 | 48 | } |
42 | | - } |
43 | | - |
44 | | - private func setupConstraints() { |
45 | | - NSLayoutConstraint.activate(constraints) |
46 | | - } |
47 | | - |
48 | | - open func configureView(_ viewModel: ViewModel?) { } |
| 49 | + |
| 50 | + private func setupConstraints() { |
| 51 | + NSLayoutConstraint.activate(constraints) |
| 52 | + } |
| 53 | + |
| 54 | + open func configureView(_ viewModel: ViewModel?) { } |
| 55 | + |
49 | 56 | } |
0 commit comments