Singleton Variable not Changing iOS
I have created a variable in a class called User its not a global variable
but it gets changed when a method is called from another class. Here is
the User class:
User.h:
@interface User : NSObject{
BOOL twitterLoggedIn;
BOOL facebookLoggedIn;
BOOL instagramLoggedIn;
BOOL googleLoggedIn;
BOOL linkedinLoggedIn;
}
+ (instancetype)data;
-(BOOL)returnInstagramState;
-(BOOL)returnTwitterState;
-(BOOL)returnFacebookState;
-(BOOL)returnGoogleState;
-(BOOL)returnLinkedinState;
-(void)setInstagramLogged:(BOOL *)turtle;
-(BOOL)returnAllOff;
@end
Method in User.m which changes the Variable + Where the Variable is Defined:
+(instancetype)data {
static User *_data = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_data = [[User alloc] init];
});
return _data;
}
- (id)init {
if (self = [super init]) {
instagramLoggedIn = NO;
twitterLoggedIn = NO;
googleLoggedIn = NO;
facebookLoggedIn = NO;
linkedinLoggedIn = NO;
}
return self;
}
-(void)setInstagramLogged:(BOOL *)turtle{
instagramLoggedIn = turtle;
}
Where I call for the value to be changed
-(void)authenticateWithTwitter{
self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL
URLWithString:@"https://api.twitter.com/"]
key:@"You
dont wanna
know that"
secret:@"Thats a
Seceret"];
[self.twitterClient
authorizeUsingOAuthWithRequestTokenPath:@"oauth/request_token"
userAuthorizationPath:@"oauth/authorize"
callbackURL:[NSURL
URLWithString:@"floadt://success"]
accessTokenPath:@"oauth/access_token"
accessMethod:@"POST"
scope:nil
success:^(AFOAuth1Token
*accessToken, id
response) {
NSLog(@"%@",accessToken);
self.accessToken
= accessToken;
[[User data]
setInstagramLogged:YES];
}
failure:^(NSError
*error) {
NSLog(@"Error:
%@", error);
}];
}
No comments:
Post a Comment