[ad_1]
I’ve two lessons with principally an identical tableViewDelegate and tableViewDataSource implementation code. Within the curiosity of leaving the code higher than I discovered it, I determine I ought to attempt to cut back duplication. That is proving to be fairly troublesome. See the instance code construction under:
class A : UICollectionViewCell {
//a bunch of code
}
extension A : UITableViewDataSource, UITableViewDelegate {
//A bunch of code that's almost an identical to the opposite class
}
class B : UIViewController {
//a bunch of code
}
extension B : UITableViewDataSource, UITableViewDelegate {
//A bunch of code that's almost an identical to the opposite class
}
Each extensions use the identical world variables from class A and B respectively. My preliminary thought was to create a superclass for sophistication A and B that already has these delegates carried out. Nonetheless, I do not assume this can work as a result of lessons A and B aren’t extending the identical class. I believe I must go too far up the category hierarchy to discover a superclass that they share.
Is there a great way to scale back this repeated code?
Thanks
[ad_2]
