<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=""><div class="">The only real way to do this today is to have two layers of protocol:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">protocol SpecialControllerBase {</div><div class="">&nbsp; var currentValueBase: SpecialValue? { get }</div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">}</div><div class="">protocol&nbsp;SpecialController: SpecialControllerBase&nbsp;{</div><div class="">&nbsp;&nbsp;associatedtype SpecialValueType : SpecialValue</div><div class="">&nbsp; var currentValue: SpecialValueType? { get }</div><div class="">}</div><div class="">extension SpecialController {</div><div class="">&nbsp; var currentValueBase: SpecialValue? { return self.currentValue }</div><div class="">}</div></blockquote><div class=""><br class=""></div>Supporting this natively is the feature called <i class="">generalized existentials,</i>&nbsp;described in the “<a href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#generalized-existentials" class="">Generics Manifesto</a>” of potential future Swift features. This has a lot of design and implementation considerations, so it’s not planned to happen right away, but it’s definitely a heavily-requested feature.<div class=""><br class=""></div><div class="">Jordan<br class=""><div class=""><br class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 2, 2016, at 12:31, Robert Nikander via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi,<br class=""><br class="">In the following code, I want to test if x is a `SpecialController`. If it is, I want to get the `currentValue` as a `SpecialValue`. How do you do this? If not with a cast, then some other technique.<br class=""><br class="">I understand the error, and that SpecialController by itself is not a simple type to cast to. But it seems like what I’m saying is logically consistent and not that complicated. Is there really no way to *say* it in Swift?<br class=""><br class=""> &nbsp;&nbsp;&nbsp;protocol SpecialController {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;associated type SpecialValueType : SpecialValue<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var currentValue: SpecialValueType? { get }<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""> &nbsp;&nbsp;&nbsp;...<br class=""> &nbsp;&nbsp;&nbsp;var x: AnyObject = ...<br class=""> &nbsp;&nbsp;&nbsp;if let sc = x as? SpecialController { &nbsp;// does not compile<br class=""><br class="">Rob<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></div></body></html>