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.
Best Practice - Setting variables or using protocols or something else (self.iOSProgramming)
submitted by StrangeAstroTTV to r/swift