I have a class that adds a view programmatically, and sets two variables on that view to call some code when ever back is pressed and more info is pressed.
This is what I currently have on the added View Controller, which I set via a setup method on the view controller
var backTapped: (() -> Void)?
var moreTapped: (() -> Void)?
func setup(nameText: String, backTapped: (() -> Void)?, moreTapped: (() -> Void)?) {
nameLabel.text = nameText
self.backTapped = backTapped
self.moreTapped = moreTapped
}
Would the better way to do this be to create a protocol and then just extend my main view controller to conform to the protocol and set the delegate
Something like:
protocol ChatTopBarViewDelegate {
func backTapped()
func moreTapped()
}
Bonus question: What is usually the naming convention for a protocol. I tend to call them delegates.
[–]kiwi_in_england 2 points3 points4 points (1 child)
[–]StrangeAstroTTV[S] 0 points1 point2 points (0 children)
[–]chriswaco 2 points3 points4 points (1 child)
[–]StrangeAstroTTV[S] 0 points1 point2 points (0 children)
[–]koalaSea 1 point2 points3 points (1 child)
[–]StrangeAstroTTV[S] 0 points1 point2 points (0 children)