<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=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On May 23, 2017, at 1:10 PM, Russell Finn via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;" class="">I'm having an issue with an NSDictionary that is passing through Swift code and back to Objective-C losing access to a method implemented by a category on NSDictionary. There is clearly some subtlety about bridged dictionaries that I'm missing, and I'd appreciate any clarification that the list can provide.</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;" class="">Specifically: I have a Swift 3 application that uses some legacy Objective-C classes. One of these classes relies on a category on NSDictionary that implements a method called `-boolValueForKey:`. </div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;" class="">In the main application, the Swift code calls a method on a remote object proxy that returns an NSDictionary, which get bridged back to a Swift dictionary (`[AnyHashable: Any]`). This bridged dictionary is passed to a method on the legacy Objective-C class that calls the `-boolValueForKey:` method from the category. At this point, a runtime exception occurs that says the dictionary object (which at this point is a `_SwiftDeferredNSDictionary`, according to the debugger) doesn’t recognize the selector `-boolValueForKey:`.</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;" class="">I can work around the issue in my code by modifying the legacy Objective-C class and inlining the implementation of `-boolValueForKey:` — but is there a better general approach?</div></div></div></blockquote><br class=""></div><div>This should work. _SwiftDeferredNSDictionary is a subclass of NSDictionary and should inherit all of NSDictionary's categories.</div><div><br class=""></div><div>What is the exact exception you get?</div><div><br class=""></div><div><br class=""></div><div>-- </div><div>Greg Parker <a href="mailto:gparker@apple.com" class="">gparker@apple.com</a> Runtime Wrangler</div><div><br class=""></div><div><br class=""></div></body></html>