I’ve mentioned a few projects that use objective-c method swizzling to change existing components for the better such as UIMenuItem-CXAImageSupport which swizzles the drawTextInRect method of a UIMenuItem allowing you to use images as a menu item.
The problem with method swizzling is that it can lead to horrendous bugs that can seem impossible to debug without a good understanding of the code used.
Here’s a tutorial from Mattt Thompson that shows how to perform method swizzling, and does a great job of explaining exactly what’s going on along with some considerations so that you can make sure your code is reasonably safe.
You can find the Matt’s method swizzling tutorial over on the NSHipster blog.
There’s also a nice thread that talks about many of the dangers on method swizzling along with some ways to avoid them over on Stack Overflow.
A nice guide on method swizzling and how to avoid potential dangers that can come up.
- Example: How To Place An Image In A UIMenuItem By Using Method Swizzling
- Objective-C Runtime Additions Allows Swizzling Without Creating A Category And More
- Easy To Use Objective-C Library For Profiling The Performance Of A Specific Method
- Open Source Library Providing Basic Generics Within Objective-C
- Avoid Retain Cycles In Objective-C
Original article: Tutorial: How To Perform Objective-C Method Swizzling And Avoid Danger
©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.




