How to make a class in Swift extend a concrete class and conform to multiple protocols? [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0
















This question already has an answer here:




  • How do I make a class conform to a protocol in swift?

    2 answers




Background



I am creating an extension for UITableViewController like so:



func attachToController<C: UIViewController>(_ sender: C, alignTo: UIView, to: ALEdge = .top , withOffset: CGFloat = 0.0)
where C: UITableViewDataSource, C:UITableViewDelegate
{
self.estimatedRowHeight = 44
..
self.delegate = sender as UITableViewDelegate
self.dataSource = sender as UITableViewDataSource
}


Currently the class that's using this extension is declared like so:



final class MyViewController: UIViewController {


then I call this in view did load:



override func viewDidLoad() {
super.viewDidLoad()
self.setupTableView()
}

..

func setupTableView() {
self.tableView.attachToController(self, alignTo: self.view, withOffset: 0.0)
..
}


But I'm getting the error




Ambiguous reference to member 'tableView'




I would like to declare MyViewController so that it extends UIViewController and also conforms to the UITableViewDataSource and UITableViewDelegate protocols.. ideas?



Note: I'm using Swift 4.2.










share|improve this question















marked as duplicate by Community Nov 23 '18 at 13:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

























    0
















    This question already has an answer here:




    • How do I make a class conform to a protocol in swift?

      2 answers




    Background



    I am creating an extension for UITableViewController like so:



    func attachToController<C: UIViewController>(_ sender: C, alignTo: UIView, to: ALEdge = .top , withOffset: CGFloat = 0.0)
    where C: UITableViewDataSource, C:UITableViewDelegate
    {
    self.estimatedRowHeight = 44
    ..
    self.delegate = sender as UITableViewDelegate
    self.dataSource = sender as UITableViewDataSource
    }


    Currently the class that's using this extension is declared like so:



    final class MyViewController: UIViewController {


    then I call this in view did load:



    override func viewDidLoad() {
    super.viewDidLoad()
    self.setupTableView()
    }

    ..

    func setupTableView() {
    self.tableView.attachToController(self, alignTo: self.view, withOffset: 0.0)
    ..
    }


    But I'm getting the error




    Ambiguous reference to member 'tableView'




    I would like to declare MyViewController so that it extends UIViewController and also conforms to the UITableViewDataSource and UITableViewDelegate protocols.. ideas?



    Note: I'm using Swift 4.2.










    share|improve this question















    marked as duplicate by Community Nov 23 '18 at 13:12


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0









      This question already has an answer here:




      • How do I make a class conform to a protocol in swift?

        2 answers




      Background



      I am creating an extension for UITableViewController like so:



      func attachToController<C: UIViewController>(_ sender: C, alignTo: UIView, to: ALEdge = .top , withOffset: CGFloat = 0.0)
      where C: UITableViewDataSource, C:UITableViewDelegate
      {
      self.estimatedRowHeight = 44
      ..
      self.delegate = sender as UITableViewDelegate
      self.dataSource = sender as UITableViewDataSource
      }


      Currently the class that's using this extension is declared like so:



      final class MyViewController: UIViewController {


      then I call this in view did load:



      override func viewDidLoad() {
      super.viewDidLoad()
      self.setupTableView()
      }

      ..

      func setupTableView() {
      self.tableView.attachToController(self, alignTo: self.view, withOffset: 0.0)
      ..
      }


      But I'm getting the error




      Ambiguous reference to member 'tableView'




      I would like to declare MyViewController so that it extends UIViewController and also conforms to the UITableViewDataSource and UITableViewDelegate protocols.. ideas?



      Note: I'm using Swift 4.2.










      share|improve this question

















      This question already has an answer here:




      • How do I make a class conform to a protocol in swift?

        2 answers




      Background



      I am creating an extension for UITableViewController like so:



      func attachToController<C: UIViewController>(_ sender: C, alignTo: UIView, to: ALEdge = .top , withOffset: CGFloat = 0.0)
      where C: UITableViewDataSource, C:UITableViewDelegate
      {
      self.estimatedRowHeight = 44
      ..
      self.delegate = sender as UITableViewDelegate
      self.dataSource = sender as UITableViewDataSource
      }


      Currently the class that's using this extension is declared like so:



      final class MyViewController: UIViewController {


      then I call this in view did load:



      override func viewDidLoad() {
      super.viewDidLoad()
      self.setupTableView()
      }

      ..

      func setupTableView() {
      self.tableView.attachToController(self, alignTo: self.view, withOffset: 0.0)
      ..
      }


      But I'm getting the error




      Ambiguous reference to member 'tableView'




      I would like to declare MyViewController so that it extends UIViewController and also conforms to the UITableViewDataSource and UITableViewDelegate protocols.. ideas?



      Note: I'm using Swift 4.2.





      This question already has an answer here:




      • How do I make a class conform to a protocol in swift?

        2 answers








      ios swift swift4 swift-extensions swift4.2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 21 at 0:22









      halfer

      14.8k759118




      14.8k759118










      asked Nov 23 '18 at 8:24









      abboodabbood

      16.1k983166




      16.1k983166




      marked as duplicate by Community Nov 23 '18 at 13:12


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Community Nov 23 '18 at 13:12


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          1














          Just add it



          final class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate


          Also if the attachToController(...) extension is on UITableViewController it won't work, I assume according to how you call it, you want it to be on UITableView






          share|improve this answer
























          • it works just fine.. i'm doing this self.tableView.attachToController

            – abbood
            Nov 23 '18 at 8:43


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Just add it



          final class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate


          Also if the attachToController(...) extension is on UITableViewController it won't work, I assume according to how you call it, you want it to be on UITableView






          share|improve this answer
























          • it works just fine.. i'm doing this self.tableView.attachToController

            – abbood
            Nov 23 '18 at 8:43
















          1














          Just add it



          final class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate


          Also if the attachToController(...) extension is on UITableViewController it won't work, I assume according to how you call it, you want it to be on UITableView






          share|improve this answer
























          • it works just fine.. i'm doing this self.tableView.attachToController

            – abbood
            Nov 23 '18 at 8:43














          1












          1








          1







          Just add it



          final class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate


          Also if the attachToController(...) extension is on UITableViewController it won't work, I assume according to how you call it, you want it to be on UITableView






          share|improve this answer













          Just add it



          final class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate


          Also if the attachToController(...) extension is on UITableViewController it won't work, I assume according to how you call it, you want it to be on UITableView







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 8:31









          olejnjakolejnjak

          483313




          483313













          • it works just fine.. i'm doing this self.tableView.attachToController

            – abbood
            Nov 23 '18 at 8:43



















          • it works just fine.. i'm doing this self.tableView.attachToController

            – abbood
            Nov 23 '18 at 8:43

















          it works just fine.. i'm doing this self.tableView.attachToController

          – abbood
          Nov 23 '18 at 8:43





          it works just fine.. i'm doing this self.tableView.attachToController

          – abbood
          Nov 23 '18 at 8:43





          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents