After reading a comment on another answer
I need to get userEMail value in multiple classes, so its wrong to send data to every class
It sounds more like you are after a singleton class. So try something like this
AuthObject.h
@interface AuthObject : NSObject
@property (nonatomic, strong) NSString *userEMail;
+ (AuthController*)authInstance;
@end
AuthObject.m
#import "AuthObject.h"
@implementation AuthObject
@synthesize userEMail = _userEMail;
static AuthObject *authObjectSharedInstance = nil;
+ (AuthObject *)authInstance
{
static dispatch_once_t instanceToken;
dispatch_once(&instanceToken, ^{
authObjectSharedInstance = [[AuthObject alloc] init];
});
return authObjectSharedInstance;
}
@end
then in another method in another class as long as you have imported AuthObject.h
somewhere you can do
- (void)someMethodIMadeUpInClass1
{
AuthObject *authObj = [AuthObject authInstance];
[authObj setUserEMail:@"myemail@address.com"];
}
then in a completely different class you can do
- (void)someMethodIMadeUpInClass2
{
AuthObject *authObj = [AuthObject authInstance];
NSLog(@"my email : %@", [authObj userEMail];
}
In theory if you're creating a singleton class and not going through a sharedInstance
(authInstance
here) then that code is broken. Attempting to hide that brokenness is just going to cause pain later on. This is why I would chose a singleton class over using NSUserDefaults
.