<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">You can try upcasting the value to NSObject first, and then performing a conditional downcast to Controller1 and Controller2. At this point the type checker will not have enough information to decide that the cast always fails, and should no longer emit a warning.<div class=""><br class=""></div><div class="">Slava<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 6, 2017, at 11:55 PM, Glen Huang &lt;<a href="mailto:heyhgl@gmail.com" class="">heyhgl@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Done, <a href="https://bugs.swift.org/browse/SR-6083" class="">https://bugs.swift.org/browse/SR-6083</a><div class=""><br class=""></div><div class="">In the mean time, is there any workaround? Or it’s not possible to check the concrete type without this issue being fixed?<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 7 Oct 2017, at 2:44 PM, Slava Pestov &lt;<a href="mailto:spestov@apple.com" class="">spestov@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Oh I see. I think the problem is that with Objective-C generics, you can always cast from Foo&lt;A&gt; to Foo&lt;B&gt;, because the type parameters do not really exist. Swift’s type checking logic for casts assumes Swift generic semantics, where in general Foo&lt;A&gt; and Foo&lt;B&gt; are unrelated types.<br class=""><br class="">Do you mind filing a bug?<br class=""><br class="">Slava<br class=""><br class=""><blockquote type="cite" class="">On Oct 6, 2017, at 11:40 PM, Glen Huang &lt;<a href="mailto:heyhgl@gmail.com" class="">heyhgl@gmail.com</a>&gt; wrote:<br class=""><br class="">NSFetchedResultsController is the class from Core Data: <br class=""><br class=""><a href="https://developer.apple.com/documentation/coredata/nsfetchedresultscontroller" class="">https://developer.apple.com/documentation/coredata/nsfetchedresultscontroller</a><br class=""><br class=""><blockquote type="cite" class="">On 7 Oct 2017, at 2:38 PM, Slava Pestov &lt;<a href="mailto:spestov@apple.com" class="">spestov@apple.com</a>&gt; wrote:<br class=""><br class="">Can you post a self-contained example, including the declaration of NSFetchedResultsController?<br class=""><br class="">Slava<br class=""><br class=""><blockquote type="cite" class="">On Oct 6, 2017, at 11:28 PM, Glen Huang via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""><br class="">Hi,<br class=""><br class="">I defined some concrete classes inheriting from a generic class like this:<br class=""><br class="">class Controller1: NSFetchedResultsController&lt;NSManagedObject&gt; {}<br class="">class Controller2: NSFetchedResultsController&lt;NSManagedObject&gt; {}<br class=""><br class="">And I assign them a shared delegate, and in the delegate method:<br class=""><br class="">func controllerWillChangeContent(_ controller: NSFetchedResultsController&lt;NSFetchRequestResult&gt;)<br class=""><br class="">I want to test the concrete type of controller, doing things differently for Controller1 and Controller2.<br class=""><br class="">But doing the following gives me a warning: Cast from 'NSFetchedResultsController&lt;NSFetchRequestResult&gt;' to unrelated type 'Controller1’ always fails<br class=""><br class="">switch controller {<br class="">case is Controller1:<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;// ...<br class="">default:<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;break<br class="">}<br class=""><br class="">I wonder what’s the correct way to check the concrete type?<br class=""><br class="">Regards,<br class="">Glen<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=""></blockquote><br class=""></blockquote><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></body></html>