views:

106

answers:

1

What is the difference between:

[[UIApplication sharedApplication] delegate]

and

UIApplicationDelegate
+5  A: 

UIApplicationDelegate is a protocol definition, which means it's a set of methods an object that conforms to it should implement.

[[UIApplication sharedApplication] delegate] is the way you have to ask for application delegate of your currently running application. That delegate should conform to UIApplicationDelegate.

pgb
Thank you. That makes sense.What about the usual MyApplicationNameAppDelegate vs [[UIApplication sharedApplication] delegate]?
Bryan
That's just usually a typecast. You would do `MyApplicationNameAppDelegate *d = (MyApplicationNameAppDelegate *)[[UIApplication sharedApplication] delegate]` and get the delegate casted to the class you use to implement it.
pgb