3

Here is the description of the delegate property of UIScrollView in apple's document

UIScrollView: UIView, NSCoding {
  ...
  weak public var delegate: UIScrollViewDelegate?
  ...
}

And the delegate property of UITableView:

UITableView: UIScrollView, NSCoding {
  ...
  weak public var delegate: UITableViewDelegate?
  ...
}

UITableView inherits from UIScrollView. But the delegate property seems to be independent from that of UIScrollView.There is no override keyword in front of it. And they belong to different types, although UITableViewDelegate inherits from UIScrollViewDelegate. I think it is against the inheriting rule of swift. And i found it did after doing some test in my own class. Here is my test code:

public class SomeClassA {
    weak public var delegate: UIScrollViewDelegate?
}

public class SomeClassB: SomeClassA {
  //reporting "property 'delegate' with type 'UITableViewDelegate?' cannot 
  //override a property with type 'UIScrollViewDelegate?'"error
  weak public var delegate: UITableViewDelegate?
}

where does the problem lie?

shellhue
  • 569
  • 6
  • 12
  • 1
    [this has more info](http://stackoverflow.com/questions/25724709/overriding-delegate-property-of-uiscrollview-in-swift-like-uicollectionview-doe?rq=1) -> Basically it says that it is the result of the underlying code being obj-c where overriding the delegate is possible. (no expert on obj-c at all) – R Menke Nov 17 '15 at 19:55
  • @R Menke yeah, i think you are right. thanks – shellhue Nov 18 '15 at 14:43
  • No problem, was very confused by it as well. Was considering a bounty on this question, but a couple of google searches later I found a possible answer. – R Menke Nov 18 '15 at 14:47

0 Answers0