How to Swizzle Framework methods?

How to perform swizzling for a framework method in objective c for OS X. It would be great if someone can explain with an example.


Thanks

Method swizzling on classes you don’t control is almost always a bad idea. Why do you want to do that?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Actually I'm trying to create a replacement class for NSTableHeaderCell that allows table column headers to have two lines of text. Previously it worked when "poseAsClass" feature was available.

Now as it is deprecated, I need an alternative to maintain the functionality of poseAsClass, so I tried implementing method swizzling.


Thanks

Hmm. Why can't you just subclass NSTableHeaderCell?

Can you please give a sample of a simple table with two lines of header (objective c, OS X)?


Thanks

I don't understand. You said you wanted to swizzle a method of NSTableHeaderCell, didn't you? Why not just make a subclass with your replacement method as a proper override, and set the custom subclass in the NSTableHeaderView? That should give the same behavior as swizzling.


That much appears straightforward, on the surface. So, I guess my question is really whether there's something else going on that rules out subclassing as a solution?

How to Swizzle Framework methods?
 
 
Q