Why does AppDelegate inherit from UIResponder?
Asked Answered
H

6

19

I noticed that when creating a new project with the iPhone Master-Detail template in Xcode 4.2 beta 4, it does:

// AppDelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate>

Why does AppDelegate inherit from UIResponder instead of NSObject?

Hosanna answered 1/8, 2011 at 0:16 Comment(4)
If you had to guess, what would you say?Clementeclementi
@Caleb, I'd guess it's a typo in Xcode 4.2 beta 4.Hosanna
You might be right and I don't want to comment too much on something still under NDA, but that wouldn't be my guess.Clementeclementi
One of its use is to continue handling returning of url from logging in via facebook or other applications ie. require authentication with-in the app.Mournful
C
14

From Converting to Storyboards Release Notes:

Note: In the current Xcode templates, 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. If you haven’t made use of this pattern in an existing application, there’s no need to adopt it for storyboards.

Cobia answered 24/7, 2013 at 3:52 Comment(0)
F
3

Check the documentation of UIResponder. Since AppDelegate can respond to touch events, it implements the UIResponder interface.

Frolicsome answered 1/8, 2011 at 0:19 Comment(0)
C
2

UIResponder is the base class for the UIKit framework. UIResponder can deal with the events.

Your AppDelegate class is the delegate class for the UIApplication which UIApplicationMain creates. AppDelegate conforms to the UIApplicationDelegate protocol.

The UIResponder class has the methods to get the window of the application focus on which all the views will be populated, so you should have a class that inherits from UIResponder in order to make the window as key.

Cloninger answered 24/7, 2013 at 3:41 Comment(0)
E
1

I would guess it is so it has access to the global undo manager.

Exudation answered 11/1, 2012 at 11:16 Comment(0)
H
1

AppDelegate inherits from UIResponder that handles iOS events. The UIResponder class defines an interface for objects that respond to and handle events.

Hijacker answered 24/7, 2013 at 7:20 Comment(0)
H
-4

UPDATE: My answer below might be wrong. I was just going by the image in the iOS documentation. But, it must be outdated.

Unless there's something new in iOS 5 and not yet documented, then I think this is a typo with this Xcode 4.2 beta 4 template. In an iOS app, the app delegate should subclass NSObject, not UIResponder, e.g.:

@interface AppDelegate : NSObject <UIApplicationDelegate>

For iOS apps, in UIKit (for Cocoa Touch, e.g., iPhone & iPad), UIApplication is the last responder in the responder chain.

For Mac OS X apps, in the Application Kit (for Cocoa, e.g., Mac), the app delegate is the last responder in the responder chain.

Hosanna answered 1/8, 2011 at 1:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.