How to Retrieve Your App Delegate Singleton Instance

Dec 14, 2009   //   by Derek van Vliet   //   Development  //  3 Comments

You should be familiar with the application delegate class if you have ever developed any kind of iPhone app. It is the class that contains your app’s applicationDidFinishLaunching which most if not all apps use as an entry point for execution. You might use it to keep track of application-level state variables or objects, for example.

As such, from time to time you will have a need to retrieve your app’s application delegate instance. You can retrieve it from anywhere within your app by running the following single line of code:

MyAppDelegateClass *app = (MyAppDelegateClass *)[[UIApplication sharedApplication] delegate];

Just be sure to replace “MyAppDelegateClass” with your own iPhone app’s application delegate class name.


  • […] Bar 12. How to Dial a Phone Number 13. How to Get Your App’s Display Name and Version 14. How to Retrieve Your App Delegate Singleton Instance 15. How to Make the iPhone Vibrate 16. How to Show the Network Activity Indicator 17. How to […]

  • You need to cast the delegate to your custom application class for this line of code to work correctly:

    MyAppDelegateClass *app = (MyAppDelegateClass *)[[UIApplication sharedApplication] delegate];

  • Good catch JL. Corrected!

Leave a comment

Our Games

Latest Tweets