<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 10, 2017 at 6:08 AM, Rod Brown via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi everyone. I found something odd that seems baked into how Cocoa Touch does protocols, but Swift cannot model it:<br>
<br>
<br>
@interface UIScrollView: UIView<br>
<br>
@property (weak, nonatomic) id <UIScrollViewDelegate> delegate;<br>
<br>
@end<br>
<br>
@interface UITableView: UIScrollView<br>
<br>
@property (weak, nonatomic) id <UITableViewDelegate> delegate;<br>
<br>
@end<br>
<br>
@protocol UITableViewDelegate: UIScrollViewDelegate<br>
...<br>
@end<br></blockquote><div><br></div><div>The problem here is that `UITableView`'s redefinition of `delegate` is not type-safe. By casting a `UITableView` reference to a `UIScrollView`, you set the `delegate` to something that doesn't conform to `UITableView`:</div><div><br></div><div><div> @interface ViewController () <UIScrollViewDelegate></div><div> @end</div><div><br></div><div> @implementation ViewController</div><div><br></div><div> - (void)viewDidLoad {</div><div> [super viewDidLoad];</div><div><br></div><div> UITableView *tableView = [[UITableView alloc] init];</div><div><br></div><div> // This line correctly generates a warning, because self isn't a UITableViewDelegate:</div><div> tableView.delegate = self;</div><div><br></div><div> // This line generates no warning:</div><div> ((UIScrollView *)tableView).delegate = self;</div><div> }</div><div><br></div><div> @end</div></div><div><br></div></div></div></div>