Mo Kong Interview Notes 2#
During an interview, I was asked a question, if you were asked to track pages and record each page, how would you do it?
Then I thought and said,
- My previous approach was to write the recording method in the viewDidAppear of each interface.
- My current approach is to declare a base class that inherits from UIViewController, and then write the log method in this class, and have all interfaces inherit from this class.
Then I was asked, what if some of my interfaces inherit from UITableViewController? I said I would write another base class for UITableViewController. And what if there are interfaces that inherit from UICollectionViewControoler or UITabBarViewController? Then, I felt embarrassed...
I really didn't know what other methods there were, but just now when I was searching for runtime, I came across a blog post, Method Swizzling and AOP Practice, and I was in tears... It's exactly the same, exactly the same, how come I didn't see it earlier?
After reading it, I felt like I cooperated well, and I mentioned the first two methods.
As for the answer, please refer to the link above, Method Swizzling and AOP. I had only heard of these two before, but today I learned something new, it wasn't in vain, yes, I'm sharing it with everyone.
Oh, and there's also a demo, the author's demo, AspectsDemo, this implementation looks really good, and it also has a sense of grandeur. You can take a look at the link first, and then check out this demo.