<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="">I have a generic type, and I want to add some methods that are available when the type parameter is Bool. <b class="">(This is in Xcode 8 beta 6, btw.)</b><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> foo<T> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>...</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">foo</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=""> T: Bool {</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>…</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">The above fails to compile, with "type 'T' constrained to non-protocol type ‘Bool’”. Is that an error? The book doesn’t say that type constraints have to be to protocols; in fact the example in the section “Type Constraint Syntax” shows a type constraint that requires T to be a subclass of SomeClass.*</div><div class=""><br class=""></div><div class="">OK, so I’ll find a protocol for “boolean-like” values that’s implemented by Bool. The Swift reference for `Bool` in Xcode doesn’t list anything. <a href="http://Swiftdoc.org" class="">Swiftdoc.org</a> shows a protocol `Boolean` that looks like exactly what I want, but my compiler’s never heard of it; is this something that snuck in post-3.0? If I switch <a href="http://Swiftdoc.org" class="">Swiftdoc.org</a> back to Swift 2.2, it shows an equivalent protocol called `BooleanType`, but if I try to use that, the compiler says "'BooleanType' has been renamed to ‘Bool’”.</div><div class=""><br class=""></div><div class="">At this point I threw my laptop at the wall.</div><div class="">Not really, but I started to miss the stability and simplicity of C++… :-p</div><div class=""><br class=""></div><div class="">How the @$*% do I do this?</div><div class=""><br class=""></div><div class="">—Jens</div><div class=""><br class=""></div><div class="">* In fact the book never seems to talk about type constraints in generic type extensions. It covers each of the two concepts, but not how to use them together.</div></body></html>