Get Updates By E-mail 

Article Written By:
Johann Dowa

Tutorial: How To Perform Objective-C Method Swizzling And Avoid Danger

  •  
  •  
  •  
  •  
  •  

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.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments