Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create AppDelegate shared Instance in iOS?

How to create sharedInstance of AppDelegate and use in my Application anywhere.

like image 222
Gaurav Gudaliya Avatar asked Dec 15 '22 09:12

Gaurav Gudaliya


2 Answers

Use like this:

In the AppDelegate.h

+ (AppDelegate *)sharedAppDelegate;

In AppDelegate.m

+ (AppDelegate *)sharedAppDelegate{
    return (AppDelegate *)[UIApplication sharedApplication].delegate;
}
like image 118
Anoop Vaidya Avatar answered Dec 24 '22 17:12

Anoop Vaidya


declare the statement in Constants.h

#define myappDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])

and you can use myappDelegate any where in the app if you declare the Constants.h in .pch file

Check this for PCH for Xcode 6

like image 20
Smile Avatar answered Dec 24 '22 18:12

Smile