I was trying to intercept a function named aFunc
in my code but I failed.
And then I tried to do the same thing with the function viewWillAppear
but this time the function was intercepted successfully.
The code and the log in console is shown below,I have been wondering and could anybody please help me out, thanks~
That is because the function is not marked as dynamic
so we cannot intercept (swizzle) the implementation.
To be more specific, Swift methods defined in NSObject
subclasses (note: not extensions) by default do not use ObjC message sending. Unless you mark it as dynamic
as @ikesyo said, it would use static or vtable dispatch.
Thanks for your reply,it works as expected.