<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="">It appears that you can’t extend a generic class/struct with a requirement that a type parameter inherit from a non-protocol:<div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Dictionary</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Key : String { … }</span></div></div><div class="">The above produces the error “Type ‘Key’ constrained to non-protocol type ‘String’”.</div><div class=""><br class=""></div><div class="">So is there a way I can add a method to a class, where the method depends on one of the type parameters being a specific type? For example, let’s say I want a “concatenatedKeys” method that returns all the Dictionary’s keys concatenated into a string with commas between them.</div><div class=""><br class=""></div><div class="">(The actual reason I’m doing this is more complicated, but it has to do with JSON encoding — JSON dictionary keys have to be strings, so I want to be type-safe and make my encoding methods available only for Dictionary<String, ___>.)</div><div class=""><br class=""></div><div class="">—Jens</div></body></html>