Swift: Add type constraints to an extension of a generic type
| Originator: | Cymerc | ||
| Number: | rdar://17484036 | Date Originated: | 6/27/2014 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | Xcode 6 Beta 2 |
| Classification: | Feature (New) | Reproducible: | Not Applicable |
Summary:
It would be really nice to be able to add methods to Array for example that only are available if the array contains Hashable or Equatable items.
Something like this:
extension Array<T: Equatable> {
contains:(object: T) -> Bool {
//code comparing objects using '==' in self here.
}
}
Steps to Reproduce:
Try to add contains and indexOf methods to array, restricting the T type parameter of array to only allow calling the method on Arrays containing Equatable items.
Expected Results:
You should be able to add the extension in the description
Actual Results:
You can't
Version:
Xcode 6 beta 2 version of Swift
Notes:
Configuration:
All
Attachments:
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!