I am working with an app using Firebase Cloud Messaging for Push Notification. After reading its documentation, I have a little confuse about "Swizzling disabled", I tried to find some tutorials which are talking about it, but unfortunately there is no any tutorials. Could you please help me to describe what exactly "swizzling" mean? and what is case we need to use it?
Thank you so much. Ryan
Method swizzling means that you change the implementation of a given function at runtime.
It is often used when you don't have access to the code of the function or if you don't want to modify the code of a library and when inheritance doesn't apply.
Basically what Firebase does: you don't have access to the Push Notifications API/functions except for the delegates that Apple exposes. By swizzling such a function, you can add some logic to what it is currently doing. (You can still call the "previous" function like you would do with super
or completely replace its original purpose).
This is how Firebase asks you to activate PUSH Notifications. It makes it easier for you to add it in your code and give Firebase a lot of flexibility as with one line in your AppDelegate they can run whatever they want.
NB: A simple example: you don't have access to the print
function, you can just use it. Instead of wrapping the print function in a custom function and replacing its usage everywhere; you could swizzle print
with one of your custom function to extend or replace its original functionality. As it is applied at runtime, you wouldn't have to change anything in your project and all print
calls would be "redirected" to your new custom function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With