今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

Mo Kong Interview Notes 2

Mo Kong Interview Notes 2#

I was asked a question during an interview, if you were asked to track pages and record each page, how would you do it?

Then I thought and said,

  1. My previous approach was to write the recording method in the viewDidAppear of each interface.
  2. 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 a base class for UITableViewController. What if there are interfaces that inherit from UICollectionViewControoler or UITabBarViewController? Then, I felt ashamed...

I really don't know what other methods there are, but just now when I was searching for runtime, I saw a blog post, Method Swizzling and AOP Practice, tears filled my eyes... It's exactly the same, exactly the same, can you believe it? Why didn't I see it earlier?

After reading it, I feel like I'm cooperating well, I mentioned both of the previous approaches
image1

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 a demo, the author's demo, AspectsDemo, this implementation looks really good, and it also has a sense of grandeur. You can first look at the link, and then check out this demo.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.