Extension of type with constraints cannot have an inheritance clause
| Originator: | jverkoey | ||
| Number: | rdar://23196859 | Date Originated: | Oct 21 2015 1:04AM EST |
| Status: | Duplicate of 21507148 | Resolved: | |
| Product: | Developer Tools | Product Version: | Version 7.1 beta 3 (7B85) Swift 2.1 |
| Classification: | Feature request | Reproducible: | Every time |
Summary:
In Swift 2.1 it is not possible to make an extension with a type constraint inherit from a protocol. This makes it hard to create an API where one might have a simple generic "model" object. This model could be able to specialize its behavior based on its content object type. This specialization would allow the model to be used as the data source for a table view, for example.
Steps to Reproduce:
Outlined in the attached playground:
import UIKit
public protocol TableCellObject {}
public class Model <ObjectType> {
public typealias Section = ((header: String?, footer: String?)?, objects: [ObjectType])
var sections: [Section]
public init(sections: [Section]) {
self.sections = sections
}
}
// Compiler error is thrown here:
extension Model: UITableViewDataSource where ObjectType: TableCellObject {
}
Expected Results:
That extending an object with type constraints would not result in a compiler error.
Actual Results:
A compiler error is thrown.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!