<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="">I need to do things differently in the shared delegate based on the controller type, so this probably won’t work. But thanks, I believe it will come in handy when I do need to branch on controllers themselves.<div class=""><br class=""></div><div class="">I do have a question though, since the method is a callback, and its signature is changed (with "Thing &amp;” added), will NSFetchedResultsController be able to find it and call it?&nbsp;</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 8 Oct 2017, at 12:14 AM, C. Keith Ray &lt;<a href="mailto:keithray@mac.com" class="">keithray@mac.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 dir="auto" class=""><div class="">Or make a base class for both Controller classes which defines todo () and override todo() in each Controller class.<br class=""><br class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">--<br class="">C. Keith Ray</span><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">*&nbsp;<a href="https://leanpub.com/wepntk" class="">https://leanpub.com/wepntk</a>&nbsp;&lt;- buy my book?<br class="">*&nbsp;</span><a href="http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf" class="">http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf</a><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class="">*&nbsp;<a href="http://agilesolutionspace.blogspot.com/" class="">http://agilesolutionspace.blogspot.com/</a></span></div></div><div class=""><br class="">On Oct 7, 2017, at 9:12 AM, C. Keith Ray &lt;<a href="mailto:keithray@mac.com" class="">keithray@mac.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div class="">You should be able to do this to avoid casting.(I think)</div><div class=""><br class=""></div><div class="">protocol Thing {</div><div class="">&nbsp; &nbsp;func todo()</div><div class="">}</div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">class Controller1: NSFetchedResultsController&lt;NSManagedObject&gt;, Thing {</span></div><div class="">&nbsp; &nbsp; func todo () {doOneThing}</div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">}</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">class Controller2: NSFetchedResultsController&lt;NSManagedObject&gt;, Thing {</span></div><div class="">&nbsp; &nbsp; func todo () {doAnotherThing}<br class="">}</div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">func controllerWillChangeContent(_ controller: Thing &amp; NSFetchedResultsController&lt;NSFetchRequestResult&gt;) {</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">&nbsp; &nbsp; controller.todo()</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">&nbsp; &nbsp; ...</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">}</span></div><div class=""><br class=""><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">--<br class="">C. Keith Ray</span><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">*&nbsp;<a href="https://leanpub.com/wepntk" class="">https://leanpub.com/wepntk</a>&nbsp;&lt;- buy my book?<br class="">*&nbsp;</span><a href="http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf" class="">http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf</a><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class="">*&nbsp;<a href="http://agilesolutionspace.blogspot.com/" class="">http://agilesolutionspace.blogspot.com/</a></span></div></div></div><div class=""><br 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=""></div><blockquote type="cite" class=""><div class=""><span class="">Hi,</span><br class=""><span class=""></span><br class=""><span class="">I defined some concrete classes inheriting from a generic class like this:</span><br class=""><span class=""></span><br class=""><span class="">class Controller1: NSFetchedResultsController&lt;NSManagedObject&gt; {}</span><br class=""><span class="">class Controller2: NSFetchedResultsController&lt;NSManagedObject&gt; {}</span><br class=""><span class=""></span><br class=""><span class="">And I assign them a shared delegate, and in the delegate method:</span><br class=""><span class=""></span><br class=""><span class="">func controllerWillChangeContent(_ controller: NSFetchedResultsController&lt;NSFetchRequestResult&gt;)</span><br class=""><span class=""></span><br class=""><span class="">I want to test the concrete type of controller, doing things differently for Controller1 and Controller2.</span><br class=""><span class=""></span><br class=""><span class="">But doing the following gives me a warning: Cast from 'NSFetchedResultsController&lt;NSFetchRequestResult&gt;' to unrelated type 'Controller1’ always fails</span><br class=""><span class=""></span><br class=""><span class="">switch controller {</span><br class=""><span class="">case is Controller1:</span><br class=""><span class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// ...</span><br class=""><span class="">default:</span><br class=""><span class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break</span><br class=""><span class="">}</span><br class=""><span class=""></span><br class=""><span class="">I wonder what’s the correct way to check the concrete type?</span><br class=""><span class=""></span><br class=""><span class="">Regards,</span><br class=""><span class="">Glen</span><br class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-users mailing list</span><br class=""><span class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br class=""></div></blockquote></div></blockquote></div></div></blockquote></div><br class=""></div></body></html>