Answer the question
In order to leave comments, you need to log in
What is wrong with delegation?
Question:
I need to do a function delegation, but I can't figure out where I went wrong or what knowledge I lack.
I have a "master file" (boss):
protocol MainViewControllerDelegate {
func openedSideBar()
}
// ниже в этом же файле
var delegate: MainViewControllerDelegate?
// еще ниже
delegate?.openedSideBar()
var mainViewControllerDelegate = MainViewController()
mainViewControllerDelegate.delegate = self
extension MainCellCollectionView: MainViewControllerDelegate {
func openedSideBar() {
print("1")
}
}
Answer the question
In order to leave comments, you need to log in
You kind of twisted everything.
I'll try to answer abstractly:
Object Senior owns the object Junior.
Object Major, satisfies the Delegate Minor protocol.
The Major object sets itself as a delegate to the Minor object. (of type mladshiy.delegate = self
)
When the junior has a sidebar, he should call the appropriate delegate method (of type delegate.openedSideBar()
)
I hope this will give you an understanding of what you lack in knowledge.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question