[Question] why is ASDelegateProxy a proxy
Hi, we'd like to know why ASDelegateProxy is a proxy, since it doesn't use any of the NSProxy's methods.
@garrettmoon @Adlai-Holler @maicki
@Yue-Wang-Google not sure I understand the question. Are you asking why it's not a subclass of NSProxy? I wrote it to do exactly what I needed (break a retain cycle created by CADisplayLink) and nothing more. Subclassing NSProxy seemed more complex. Is there an issue you're seeing?
Oh we were asking why ASDelegateProxy is a subclass of NSProxy rather than a NSObject. Since ASDelegateProxy and its subclasses do not use any NSProxy features. See https://github.com/facebook/AsyncDisplayKit/blob/master/AsyncDisplayKit/Details/ASDelegateProxy.h#L28
Whoops, I totally misunderstood and thought you were referring to ASWeakProxy.
Looking into it a bit, ASWeakProxy probably should inherit from NSProxy.
NSProxy doesn't inherit from NSObject and implements far fewer methods allowing your proxy object to override more points.
@garrettmoon as you pointed out, NSProxy implements a lot less methods than NSObject.
I had an issue in one of my app with ASDelegateProxy. I had some code that was testing the class of a UIScrollView delegate with isKindOf: and that will crash on an NSProxy object (because NSProxy doesn't implement isKindOf).
I ended up using isProxy to avoid the crash.
Back to the original question, if ASDelegateProxy doesn't actually use the NSProxy APIs, do we have a substantial added benefit of having it an NSProxy instead of an NSObject ?
Note: I'm not very familiar with NSProxy, so there is potentially one (or several) very valid reason to use it.
What do you mean, it doesn't use the NSProxy APIs? NSProxy doesn't have specific APIs that a subclass would call, it's intention appears to be a minimal object to support proxying – more minimal than even NSObject (it doesn't even have an init method!). So the advantage is it is lightweight and allows for proxying methods on NSObject without explicitly overriding them. At least that's my understanding :)
Like I said I'm not an expert in NSProxy so I'm gonna lean toward your advice.
I was under the impression that the interesting APIs for NSProxy were
methodSignatureForSelector: and forwardInvocation:. In the case of ASDelegateProxy, forwardInvocation is basically a no-op.
Thanks for the explanation, I definitely read more about NSProxy today than I ever did in the past 8 years ^^.
Ah, found a stack overflow that might explain better what I was trying to say:
http://stackoverflow.com/questions/18284724/nsproxy-vs-nsobject
Essentially, if we wanted to proxy anything that NSObject implemented, we'd need to override that method and call it on our proxy object. By not subclassing NSObject we can avoid that because forwardingTargetForSelector: will get called. If it was implemented in NSObject and we didn't override it, forwardingTargetForSelector: would never be called.
Thanks @garrettmoon
Thanks @garrettmoon for your explanation!