Q:

How can I add the same methods to different classes?

Is it possible to add the same methods to different classes?
Example:
class FilterableTable: UITableViewController { ... }
class FilterableCollection: UICollectionViewController { ... }

extension FilterableTable, FilterableCollection { // I know this line is wrong
  func filterItems(){ print('filtered!') }
}

How can I add the same Foo method to a UICollectionViewController?
Protocols allow to declare only needed methods signatures, but I need exactly the same method (with body), to avoid copy-paste...

A:

Actual answer: Use the Delegates, Luke!
class FilterableTable: UITableViewController {
    var filterDelegate: FilterDelegate! 
    func viewDidLoad(){
        filterDelegate = Filter()
    }
}
class FilterableCollection: UICollectionViewController {
    var filterDelegate: FilterDelegate! 
    func viewDidLoad(){
        filterDelegate = Filter()
    }
}

protocol FilterDelegate {
    func filterItems()
}

class Filter: FilterDelegate {
    func filterItems() {
        print("Hooray!")
    }
}

