5 ms·
Is there an advantage to method swizzling instead of just subclassing UIApplication?
by garrettlarson 12y ago
Is there an advantage to method swizzling instead of just subclassing UIApplication?
- Greenisus 12y agoIn general, people avoid subclassing in Cocoa/Cocoa Touch because you often don't know the implementation of the parent class and what effect using a subclass might have (is the parent a class cluster, etc). Many Cocoa/Cocoa Touch APIs (NSDictionary, UIButton, etc) recommend composition over subclassing, so you'll often see people do things like add a category or swizzle methods. I've done a little method swizzling myself, but it makes me a little nervous about side effects, so I try to only use that technique as a very last resort. I think what they're doing here is pretty clever, but I would be uneasy about using it in a shipped app.