<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="">good point - type safety would prevent it from compiling.<div class=""><br class=""></div><div class="">also, the controllers are subclasses of NSFetchedResultsController<NSManagedObject></div><div class=""><div class=""><br class=""></div><div class="">but the delegate method takes a different type: NSFetchedResultsController<NSFetchRequestResult></div><div class=""><br class=""></div><div class="">NSManagedObject != NSFetchRequestResult</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><div class=""><div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">--<br class="">C. Keith Ray<br class="">Senior Software Engineer / Trainer / Agile Coach<br class="">* <a href="http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf" class="">http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf</a><br class=""></div><div style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div></div><br class="Apple-interchange-newline">
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Oct 7, 2017, at 10:32 PM, Glen Huang <<a href="mailto:heyhgl@gmail.com" class="">heyhgl@gmail.com</a>> 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="">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 &” added), will NSFetchedResultsController be able to find it and call it? </div><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 8 Oct 2017, at 12:14 AM, C. Keith Ray <<a href="mailto:keithray@mac.com" class="">keithray@mac.com</a>> 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="">* <a href="https://leanpub.com/wepntk" class="">https://leanpub.com/wepntk</a> <- buy my book?<br class="">* </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="">* <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 <<a href="mailto:keithray@mac.com" class="">keithray@mac.com</a>> 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=""> 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<NSManagedObject>, Thing {</span></div><div class=""> 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<NSManagedObject>, Thing {</span></div><div class=""> 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 & NSFetchedResultsController<NSFetchRequestResult>) {</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""> controller.todo()</span></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="">}</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="">* <a href="https://leanpub.com/wepntk" class="">https://leanpub.com/wepntk</a> <- buy my book?<br class="">* </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="">* <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 <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> 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<NSManagedObject> {}</span><br class=""><span class="">class Controller2: NSFetchedResultsController<NSManagedObject> {}</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<NSFetchRequestResult>)</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<NSFetchRequestResult>' 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=""> // ...</span><br class=""><span class="">default:</span><br class=""><span class=""> 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></div></div></blockquote></div><br class=""></div></div></div></div></body></html>