Skip to content

Commit

Permalink
convert custom init in views to convenience init
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 12, 2020
1 parent 85d2440 commit 93bf59a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion GHFollowers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@
7D98BB4E242A7BD5006C53E9 /* Components */ = {
isa = PBXGroup;
children = (
7DA45F7D2433DCE700AB426F /* ViewControllers */,
7DA45F78242FB8DB00AB426F /* Labels */,
7DA45F7D2433DCE700AB426F /* ViewControllers */,
7DA45F77242FB8C300AB426F /* ImageViews */,
7DA45F76242FB8A000AB426F /* TextFields */,
7DA45F75242FB89900AB426F /* Buttons */,
Expand Down
Binary file not shown.
5 changes: 2 additions & 3 deletions GHFollowers/Components/Buttons/GFButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ class GFButton: UIButton {


// custom initializer to pass title and color when we init a new button
init(backgroundColor: UIColor, title: String ){
convenience init(backgroundColor: UIColor, title: String ){
// don't need a frame dimension for this one
super.init(frame: .zero)
self.init(frame: .zero)
self.backgroundColor = backgroundColor
// set title and state of button (normal, pressed, disabled ecc)
self.setTitle(title, for: .normal)
configure()
}


Expand Down
6 changes: 2 additions & 4 deletions GHFollowers/Components/Labels/GFBodyLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ class GFBodyLabel: UILabel {
}


init(textAlignment: NSTextAlignment) {
super.init(frame: .zero)

convenience init(textAlignment: NSTextAlignment) {
self.init(frame: .zero)
self.textAlignment = textAlignment
configure()
}


Expand Down
5 changes: 2 additions & 3 deletions GHFollowers/Components/Labels/GFTitleLabel-Secondary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ class GFTitleLabel_Secondary: UILabel {
}


init(fontSize: CGFloat) {
super.init(frame: .zero)
convenience init(fontSize: CGFloat) {
self.init(frame: .zero)
font = UIFont.systemFont(ofSize: fontSize, weight: .medium)

configure()
}


Expand Down
12 changes: 8 additions & 4 deletions GHFollowers/Components/Labels/GFTitleLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ class GFTitleLabel: UILabel {
}


init(textAlignment: NSTextAlignment, fontSize: CGFloat) {
super.init(frame: .zero)
// with a concenience inti we have to call the designated init of the class
// and if we need to init the class with our custom init, here for example configure() will be called anyway
// this way can have more custom initializers and dont have to call the functions to each one of them

// With a convenience init we can also give default values to paramteres so fpr example:
// if we have a super customized view that takes 5-6 params but we dont need to use all of them we can just pass the ones we need
convenience init(textAlignment: NSTextAlignment, fontSize: CGFloat) {
self.init(frame: .zero)

self.textAlignment = textAlignment
self.font = UIFont.systemFont(ofSize: fontSize, weight: .bold)

configure()
}


Expand Down
5 changes: 2 additions & 3 deletions GHFollowers/Components/Views/GFEmptyStateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ class GFEmptyStateView: UIView {
}

// with the customs inits we can pass params when we call this view and initialize them
init(message: String) {
super.init(frame: .zero)
convenience init(message: String) {
self.init(frame: .zero)
messageLabel.text = message
configure()
}


Expand Down

0 comments on commit 93bf59a

Please sign in to comment.