-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add condition to Selector call #694
base: master
Are you sure you want to change the base?
Conversation
((void(*)(id, SEL))objc_msgSend)( | ||
slf, swizzledSelector | ||
); | ||
if ([slf respondsToSelector:swizzledSelector]) { | ||
((void(*)(id, SEL))objc_msgSend)( | ||
slf, swizzledSelector | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this check is necessary, since NSURLConnection
will always implement -cancel
. Do you agree?
|
||
((void(*)(id, SEL))objc_msgSend)( | ||
slf, swizzledSelector | ||
); | ||
if ([slf respondsToSelector:swizzledSelector]) { | ||
((void(*)(id, SEL))objc_msgSend)( | ||
slf, swizzledSelector | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
((void(*)(id, SEL, id, id, id))objc_msgSend)( | ||
slf, swizzledSelector, request, queue, wrapper | ||
); | ||
if ([slf respondsToSelector:swizzledSelector]) { | ||
((void(*)(id, SEL, id, id, id))objc_msgSend)( | ||
slf, swizzledSelector, request, queue, wrapper | ||
); | ||
} | ||
} else { | ||
((void(*)(id, SEL, id, id, id))objc_msgSend)( | ||
slf, swizzledSelector, request, queue, completion | ||
); | ||
if ([slf respondsToSelector:swizzledSelector]) { | ||
((void(*)(id, SEL, id, id, id))objc_msgSend)( | ||
slf, swizzledSelector, request, queue, completion | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These as well, if I am reading correctly and these are on NSURLConnection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stopped reviewing the PR when I realized just how many of these changes you made.
Can you add the check in the one place you need it instead of everywhere? There is an overhead to using respondsToSelector:
, so we should only use it when we know the method might be optional, not in cases where we are swizzling methods that are guaranteed to exist.
When I created the
URLSessionDelegate
implementation, app crashed because I didn't implement some optional protocol methods andslf
doesn't respond to those method selectors.For example, for protocol
URLSessionDataDelegate
I didn't implement functionoptional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)