Fine Man
Fine Man

Reputation: 465

Why does class AppDelegate inherit from UIResponder?

There is already a question like this that was answered, however, I was not satisfied with the answer: Why does AppDelegate inherit from UIResponder?.

I'd like more specifics, as I am trying to understand the architecture of an iOS app.

As far as I know, UIResponder is for things that "respond" to external forces (i.e. touch events, motion events, etc.). How come the initialization of an application needs to be a UIResponder? Maybe I'm not understanding what the instance of AppDelegate does.

Upvotes: 1

Views: 626

Answers (1)

Witterquick
Witterquick

Reputation: 6140

The application delegate class inherits from UIResponder.

This is so that the delegate instance can participate in the responder chain and so handle application-level actions.

Edit:

As of iOS 5 there is a step 6: The app delegate gets the final word on events. Beginning with iOS 5 the app delegate inherits from UIResponder and no longer from NSObject as it did before.

In short: first the view, if the view has a view controller then that, next the superview until the top of the hierarchy, the window. From there to the application and finally to the app delegate.

The addition of the app delegate as potential responder is a welcome addition since we rarely – if ever – subclass UIApplication or UIWindow. But we always have our own app delegate if only to create the window and add the rootViewController in the application:didFinishLaunching… delegate method. So this happens to be the de facto best place for a responder to fall back to if there is none in the entire view hierarchy.

Taken from:

https://www.cocoanetics.com/2012/09/the-amazing-responder-chain/

Upvotes: 3

Related Questions