<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">You can't do this yet, but it's on the roadmap: <a href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances-" class="">https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances-</a><div class=""><br class=""></div><div class="">Austin</div><div class=""><br class=""><div style=""><blockquote type="cite" class=""><div class="">On Jul 9, 2016, at 10:54 PM, 褚晓敏 via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello, every one. I want to extend a struct to conform to a protocol, while it’s itself a generic and needs a constraint. So I wrote this: (Swift 3)<br class=""><br class="">``` swift<br class="">struct Polynomial<Field: Number> {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>//definition goes here<br class="">}<br class=""><br class="">extension Polynomial: CustomStringConvertible where Field: CustomStringConvertible {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>//implementation goes here<br class="">}<br class="">```<br class=""><br class="">Then I receive an error message from the compiler:<br class="">Extension of type 'Polynomial' with constraints cannot have an inheritance clause<br class=""><br class="">This is the only way I know to do this(theoretically), but unfortunately it doesn’t work.<br class=""><br class="">So, how can I achieve this? What syntax should be employed?<br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></body></html>