Skip to content

Commit

Permalink
Implement ViewCodeProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Emerson Mendes Filho committed May 23, 2021
1 parent f43956a commit b7a76a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions ViewCodeGuide/ViewCodeGuide/Source/MyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ final class MyView: UIView {
super.init(frame: .zero)
self.backgroundColor = .orange

setupHierarchy()
setupConstraints()
build()
}

@available(*, unavailable)
Expand All @@ -28,6 +27,9 @@ final class MyView: UIView {

return view
}()
}

extension MyView: ViewCodeProtocol {

func setupHierarchy() {
addSubview(titleSubtitleView)
Expand All @@ -38,4 +40,8 @@ final class MyView: UIView {
titleSubtitleView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16).isActive = true
titleSubtitleView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16).isActive = true
}

func additionalSetup() {
backgroundColor = .orange
}
}
6 changes: 4 additions & 2 deletions ViewCodeGuide/ViewCodeGuide/Source/TitleSubtitleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class TitleSubtitleView: UIView {

super.init(frame: .zero)

setupHierarchy()
setupConstraints()
build()
}

@available(*, unavailable)
Expand All @@ -45,6 +44,9 @@ final class TitleSubtitleView: UIView {

return subtitleLabel
}()
}

extension TitleSubtitleView: ViewCodeProtocol {

func setupHierarchy() {
addSubview(titleLabel)
Expand Down
4 changes: 4 additions & 0 deletions ViewCodeGuide/ViewCodeGuide/Source/ViewCodeProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ protocol ViewCodeProtocol {

func setupHierarchy()
func setupConstraints()
func additionalSetup()
}

extension ViewCodeProtocol {

func build() {
setupHierarchy()
setupConstraints()
additionalSetup()
}

func additionalSetup() { }
}

0 comments on commit b7a76a1

Please sign in to comment.