Hi everyone. I found something odd that seems baked into how Cocoa Touch does 
protocols, but Swift cannot model it:


@interface UIScrollView: UIView

@property (weak, nonatomic) id <UIScrollViewDelegate> delegate;

@end

@interface UITableView: UIScrollView

@property (weak, nonatomic) id <UITableViewDelegate> delegate;

@end

@protocol UITableViewDelegate: UIScrollViewDelegate
...
@end



Subclasses can further specify the conformance of a property’s 
protocol-conforming object to state a further type on that property. I tried to 
do something extremely similar today in Swift, and it failed, saying the 
protocols were different:


class SourceBar: UIScrollView {
        
        override var delegate: SourceBarDelegate? {
                get { return super.delegate as? SourceBarDelegate }
                set { super.delegate = newValue }
        }

} 


@objc protocol SourceBarDelegate: UIScrollViewDelegate {
        func foo()
}


Considering the fact that the protocol SourceBarDelegate conforms to 
UIScrollViewDelegate, I can’t see why this override should fail. Can anyone 
enlighten me as to why this is a limitation in the language?

Thanks,

Rod
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to