This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewTraverser { | |
private func traverseSuperViews(view: UIView) -> [Int : UIView] { | |
var views: [Int: UIView] = [:] | |
var inputView: UIView? = view | |
while inputView != nil { | |
guard let tag = inputView?.tag, let view = inputView else { continue } | |
views[tag] = view | |
inputView = view.superview | |
} | |
return views |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewTraverser { | |
// Traverse superviews | |
private func checkForSuper(view: UIView?, views: [Int: UIView]) -> UIView? { | |
guard let view = view else { return nil } | |
if views[view.tag] != nil { | |
return view | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
let viewOne = UIView() | |
let viewTwo = UIView() | |
let viewThree = UIView() | |
let intermediaryView = UIView() | |
let viewSuper = UIView() | |
let traverser = ViewTraverser() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
// Properties | |
override func viewDidLoad() { | |
// setup | |
let nameView = traverser.commonSuper(viewOne: viewOne, viewTwo: viewTwo) | |
print(nameView?.tag) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainViewController: UIViewController { | |
@IBOutlet var mainView: MainView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
mainView.myButton.addTarget(self, action: #selector(buttonTap), for: .touchUpInside) | |
} | |
func buttonTap() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainView: UIView { | |
@IBOutlet weak var myTextfield: UITextField! | |
@IBOutlet weak var myButton: UIButton! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol MainViewDelegate: class { | |
func searchButtonTappedWithTerm(with searchTerm: String) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainView: UIView { | |
@IBOutlet private weak var myTextfield: UITextField! | |
@IBOutlet private weak var myButton: UIButton! | |
weak var delegate: MainViewDelegate? | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
myButton.addTarget(self, action: #selector(buttonTap), for: .touchUpInside) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: MainViewDelegate { | |
func searchButtonTappedWithTerm(with searchTerm: String) { | |
print("The text in UITextField is: \(searchTerm)") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainViewController: UIViewController { | |
@IBOutlet var mainView: MainView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
mainView.delegate = self | |
} | |
} |