<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="">In the following code, I get an error on the line indicated (4th from the bottom) that "Protocol 'APIEndPoint' can only be used as a generic constraint because it has Self or associated type requirements” I understand this is because the APIEndPoint protocol contains a type alias. However I don’t understand why this means it can’t be used as a type? I simply want the init method I’m defining to be able to accept any object/enum that conforms to the APIEndPoint protocol.<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class="">protocol<span style="color: rgb(0, 0, 0);" class=""> API {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(195, 34, 117);" class="">static</span> <span style="color: rgb(195, 34, 117);" class="">var</span> baseUrl : <span style="color: rgb(112, 61, 170);" class="">String</span> { <span style="color: rgb(195, 34, 117);" class="">get</span> };</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 18px;" class=""><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(195, 34, 117);" class="">protocol</span> APIEndPoint {</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(195, 34, 117);" class="">typealias</span> ParentAPI : API</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(195, 34, 117);" class="">var</span> path: <span style="color: rgb(112, 61, 170);" class="">String</span> { <span style="color: rgb(195, 34, 117);" class="">get</span> }</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(195, 34, 117);" class="">func</span> urlString() -> <span style="color: rgb(112, 61, 170);" class="">String</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(60, 130, 140);" class=""><span style="color: rgb(195, 34, 117);" class="">extension</span><span style="color: rgb(0, 0, 0);" class=""> </span>APIEndPoint<span style="color: rgb(0, 0, 0);" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(195, 34, 117);" class="">func</span> urlString() -> <span style="color: rgb(112, 61, 170);" class="">String</span> {</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(195, 34, 117);" class="">return</span> <span style="color: rgb(83, 154, 164);" class="">ParentAPI</span>.baseUrl + <span style="color: rgb(83, 154, 164);" class="">path</span>;</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; min-height: 18px;" class=""><br class=""></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class="">extension<span style="color: rgb(0, 0, 0);" class=""> </span><span style="color: rgb(97, 34, 174);" class="">NSURL</span><span style="color: rgb(0, 0, 0);" class=""> {</span></div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(195, 34, 117);" class="">convenience</span> <span style="color: rgb(195, 34, 117);" class="">init</span>(instance:<span style="color: rgb(60, 130, 140);" class="">APIEndPoint</span>) { //error here</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(195, 34, 117);" class="">self</span>.<span style="color: rgb(195, 34, 117);" class="">init</span>(string:instance.urlString())!</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">If I change that line to `<span style="font-family: Menlo; font-size: 15px; color: rgb(195, 34, 117);" class="">convenience</span><span style="font-family: Menlo; font-size: 15px;" class=""> </span><span style="font-family: Menlo; font-size: 15px; color: rgb(195, 34, 117);" class="">init</span><span style="font-family: Menlo; font-size: 15px;" class=""><T:</span><span style="font-family: Menlo; font-size: 15px; color: rgb(60, 130, 140);" class="">APIEndPoint</span><span style="font-family: Menlo; font-size: 15px;" class="">>(instance:</span><span style="font-family: Menlo; font-size: 15px; color: rgb(97, 34, 174);" class="">T</span><span style="font-family: Menlo; font-size: 15px;" class="">) {`</span>then there is no problem.</div><div class=""><br class=""></div><div class="">Also if I split the APIEndPoint protocol in 2, like so:</div><div class=""><br class=""></div><div class=""><span style="font-family: Menlo; font-size: 15px; color: rgb(195, 34, 117);" class="">protocol</span><span style="font-family: Menlo; font-size: 15px;" class=""> </span><span style="font-family: Menlo; font-size: 15px;" class="">APIEndPointBase {</span></div><div class=""><div style="font-family: Menlo; font-size: 15px; margin: 0px; line-height: normal;" class=""> <span style="color: rgb(195, 34, 117);" class="">var</span> path: <span style="color: rgb(112, 61, 170);" class="">String</span> { <span style="color: rgb(195, 34, 117);" class="">get</span> }</div><div style="font-family: Menlo; font-size: 15px; margin: 0px; line-height: normal;" class=""> <span style="color: rgb(195, 34, 117);" class="">func</span> urlString() -> <span style="color: rgb(112, 61, 170);" class="">String</span></div></div><div style="font-family: Menlo; font-size: 15px; margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; font-size: 15px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(195, 34, 117);" class="">protocol</span> APIEndPoint : APIEndPointBase {</div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: rgb(195, 34, 117);" class="">typealias</span> ParentAPI : API</div><div style="margin: 0px; line-height: normal;" class="">}</div></div><div class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Then the change the line with the error to:</div></div><div class=""><br class=""></div><div class=""><span style="font-family: Menlo; font-size: 15px; color: rgb(195, 34, 117);" class="">convenience</span><span style="font-family: Menlo; font-size: 15px;" class=""> </span><span style="font-family: Menlo; font-size: 15px; color: rgb(195, 34, 117);" class="">init</span><span style="font-family: Menlo; font-size: 15px;" class="">(instance:</span><span style="font-family: Menlo; font-size: 15px; color: rgb(60, 130, 140);" class="">APIEndPointBase</span><span style="font-family: Menlo; font-size: 15px;" class="">) {</span></div><div class=""><span style="font-family: Menlo; font-size: 15px;" class=""><br class=""></span></div><div class="">then there is also no error.</div><div class=""><br class=""></div><div class="">The ability to work around this error makes it seem like the error is pointless. Even if I used the ParentAPI typealias with the protocol definition, I don’t see why I can’t use it as I have in the first code segment. Why does having Self or associated type requirements mean that the protocol can only be used as a generic constraint?</div><div class=""><br class=""></div><div class="">Apologies if I have posted this incorrectly, this is the first time I’ve used a mailing list</div><div class=""><br class=""></div><div class="">Jonathan</div></body></html>