diff --git a/GHFollowers.xcodeproj/project.pbxproj b/GHFollowers.xcodeproj/project.pbxproj index 8ac94c8..b7d3fe4 100644 --- a/GHFollowers.xcodeproj/project.pbxproj +++ b/GHFollowers.xcodeproj/project.pbxproj @@ -42,6 +42,7 @@ 7DB7350F243F8AC100E7B09B /* FavoriteCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7350E243F8AC100E7B09B /* FavoriteCell.swift */; }; 7DB7351224409BFE00E7B09B /* GFTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7351124409BFE00E7B09B /* GFTabBarController.swift */; }; 7DB735142443929200E7B09B /* GFDataLoadingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB735132443929200E7B09B /* GFDataLoadingVC.swift */; }; + 7DB7351624447F5800E7B09B /* UIView+EXt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7351524447F5800E7B09B /* UIView+EXt.swift */; }; 7DFAC88A242A86D200F5780C /* GFAlertContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */; }; /* End PBXBuildFile section */ @@ -83,6 +84,7 @@ 7DB7350E243F8AC100E7B09B /* FavoriteCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteCell.swift; sourceTree = ""; }; 7DB7351124409BFE00E7B09B /* GFTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFTabBarController.swift; sourceTree = ""; }; 7DB735132443929200E7B09B /* GFDataLoadingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFDataLoadingVC.swift; sourceTree = ""; }; + 7DB7351524447F5800E7B09B /* UIView+EXt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+EXt.swift"; sourceTree = ""; }; 7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFAlertContainerView.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -170,6 +172,7 @@ 7D98BB4B242A7327006C53E9 /* UIViewController+EXT.swift */, 7DB735082438AD0F00E7B09B /* Date+Ext.swift */, 7DB7350A2438AD9000E7B09B /* String+Ext.swift */, + 7DB7351524447F5800E7B09B /* UIView+EXt.swift */, ); path = Extensions; sourceTree = ""; @@ -357,6 +360,7 @@ files = ( 7DFAC88A242A86D200F5780C /* GFAlertContainerView.swift in Sources */, 7D98BB4224291DF3006C53E9 /* GFTextField.swift in Sources */, + 7DB7351624447F5800E7B09B /* UIView+EXt.swift in Sources */, 7D98BB3E242907BB006C53E9 /* FavoriteListVC.swift in Sources */, 7D98BB40242917E4006C53E9 /* GFButton.swift in Sources */, 7D98BB3C24290771006C53E9 /* SearchVC.swift in Sources */, diff --git a/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate b/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate index 1510587..066dcc3 100644 Binary files a/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate and b/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/GHFollowers/Components/ViewControllers/GFAlertVC.swift b/GHFollowers/Components/ViewControllers/GFAlertVC.swift index aa3b553..55956b2 100644 --- a/GHFollowers/Components/ViewControllers/GFAlertVC.swift +++ b/GHFollowers/Components/ViewControllers/GFAlertVC.swift @@ -39,6 +39,9 @@ class GFAlertVC: UIViewController { super.viewDidLoad() view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.75) + // we can add subviews like this in the begining + view.addSubviews(containerView, titleLabel, CTAButton, messageLabel) + configureContainerView() configureTitleLabel() configureButton() @@ -50,7 +53,7 @@ class GFAlertVC: UIViewController { // MARK: UI Functions func configureContainerView() { - view.addSubview(containerView) + //view.addSubview(containerView) NSLayoutConstraint.activate([ // center vertically to screen @@ -66,7 +69,8 @@ class GFAlertVC: UIViewController { func configureTitleLabel() { - containerView.addSubview(titleLabel) + //containerView.addSubview(titleLabel) + // Nil Coalescing ?? -- if nil use what comes after the ?? -- titleLabel.text = alertTitle ?? "Something went wrong" @@ -80,7 +84,7 @@ class GFAlertVC: UIViewController { func configureButton() { - containerView.addSubview(CTAButton) + //containerView.addSubview(CTAButton) CTAButton.setTitle(buttonTitle ?? "Ok", for: .normal) CTAButton.addTarget(self, action: #selector(dismissVC), for: .touchUpInside) @@ -94,7 +98,7 @@ class GFAlertVC: UIViewController { func configureMessageLabel() { - containerView.addSubview(messageLabel) + //containerView.addSubview(messageLabel) messageLabel.text = message ?? "Unable to complete request" messageLabel.numberOfLines = 4 diff --git a/GHFollowers/Components/ViewControllers/GFUserInfoheaderVC.swift b/GHFollowers/Components/ViewControllers/GFUserInfoheaderVC.swift index 432fd07..e9038a0 100644 --- a/GHFollowers/Components/ViewControllers/GFUserInfoheaderVC.swift +++ b/GHFollowers/Components/ViewControllers/GFUserInfoheaderVC.swift @@ -68,12 +68,15 @@ class GFUserInfoheaderVC: UIViewController { // add all the subView here func addSubViews() { - view.addSubview(avatarImageView) - view.addSubview(usernameLabel) - view.addSubview(nameLabel) - view.addSubview(locationImageView) - view.addSubview(locationLabel) - view.addSubview(bioLabel) + + view.addSubviews( + avatarImageView, + usernameLabel, + nameLabel, + locationImageView, + locationLabel, + bioLabel + ) } diff --git a/GHFollowers/Components/ViewControllers/ItemInfoVCs-SuperClass+SubClass/GFItemInfoVC.swift b/GHFollowers/Components/ViewControllers/ItemInfoVCs-SuperClass+SubClass/GFItemInfoVC.swift index 1453381..3a8df45 100644 --- a/GHFollowers/Components/ViewControllers/ItemInfoVCs-SuperClass+SubClass/GFItemInfoVC.swift +++ b/GHFollowers/Components/ViewControllers/ItemInfoVCs-SuperClass+SubClass/GFItemInfoVC.swift @@ -69,9 +69,9 @@ class GFItemInfoVC: UIViewController { private func layoutUI() { - view.addSubview(stackView) - view.addSubview(actionButton) - + // custom extension + view.addSubviews(stackView, actionButton) + stackView.translatesAutoresizingMaskIntoConstraints = false let padding: CGFloat = 20 diff --git a/GHFollowers/Extensions/UIView+EXt.swift b/GHFollowers/Extensions/UIView+EXt.swift new file mode 100644 index 0000000..810f359 --- /dev/null +++ b/GHFollowers/Extensions/UIView+EXt.swift @@ -0,0 +1,24 @@ +// +// UIView+EXt.swift +// GHFollowers +// +// Created by Vasileios Gkreen on 13/04/2020. +// Copyright © 2020 Vasileios Gkreen. All rights reserved. +// + +import UIKit + +extension UIView { + + + // VARIADIC PARAMETERS + // add 3 dots after the parameter and we can add as many params as we want that are all repreented in an array + // exactly as a rest operator in JS + func addSubviews(_ views: UIView...) { + for view in views { + addSubview(view) + } + } + + +}