[swift-dev] NSProxy dynamic casting to Swift or ObjC class behaves differently

Brent Royal-Gordon brent at architechies.com
Wed Jun 8 19:37:13 CDT 2016


> In my use case, I have a framework, and I want to switch developer's some delegate object with my NSProxy standin, listen delegate method myself, then forward to the developer's original delegate object.
> 
> It was working without any issues for delegate objects which are Objective-C classes. But, it fails for Swift types because dynamic casting does not work anymore.
> 
> So, do you have any suggestions about how can I handle this interception functionality without NSProxy? 

Make your proxy object explicitly conform to the the delegate protocol you're trying to monitor, and have it call through to the original delegate. Boilerplate-y? Yeah, totally. But Swift simply isn't designed for what you're trying to do.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-dev mailing list