Method swizzling

I have to swizzle UIApplicationDelegates in an Universal Framework.

I have to swizzle UIApplicationDelegates in an Universal Framework.

Why?

Method swizzling is a technique of last resort; you should only use it if you have no other options. Fortunately, in many cases there are better options. If you can explain you’re high-level goal, we should be able to point you in the right direction.

Share and Enjoy

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

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

WWDC runs Mon, 13 Jun through to Fri, 17 Jun. During that time all of DTS will be at the conference, helping folks out face-to-face. http://developer.apple.com/wwdc/

My aim is to create an Universal Framework which handles Push Notifications. So the delegates called for Push Notification implementation will be present in SDK instead of AppDelegate class of the application. Get device token and notifications in the framework and then redirect them to the application.

My aim is to create an Universal Framework which handles Push Notifications. So the delegates called for Push Notification implementation will be present in SDK instead of AppDelegate class of the application.

Don’t do this via method swizzling. Instead, publish routines in your framework that the app is expected to call when various app delegate events occur. While this makes your framework a little trickier to adopt, it avoids the need for method swizzling (which is almost always a bad idea) and makes the interface between the app and your framework explicit (which is always a good idea).

Share and Enjoy

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

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

WWDC runs Mon, 13 Jun through to Fri, 17 Jun. During that time all of DTS will be at the conference, helping folks out face-to-face. http://developer.apple.com/wwdc/

Method swizzling
 
 
Q