Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why not subclass UIApplication? Why use a delegate?

Instead of using an application delegate so that the UIApplication singleton can call the delegate methods at predefined time, what are the advantages and disadvantages of just subclassing UIApplication? (update: why does the iOS architecture use the application delegate instead of letting people write an application by subclassing UIApplication and overriding its various methods?)

That's because when we create a new UIView control, we subclass UIView (update: or we subclass UIViewController too). So why for the case of application, we don't subclass UIApplication but use delegation instead?

like image 396
Jeremy L Avatar asked May 26 '12 04:05

Jeremy L


1 Answers

Again, from the documentation:

Subclassing Notes

You might decide to subclass UIApplication to override sendEvent: or sendAction:to:from:forEvent: to implement custom event and action dispatching. However, there is rarely a valid need to extend this class; the application delegate (UIApplicationDelegate is sufficient for most occasions. If you do subclass UIApplication, be very sure of what you are trying to accomplish with the subclass.

like image 127
Kaan Dedeoglu Avatar answered Nov 15 '22 09:11

Kaan Dedeoglu