I'm using Parse as a mobile back end to my application. I have added 2 boolean column to my 'User' data table (User class) 'coach' and 'club' basically stating are they a coach or a club. During login need to perform if statements based on the boolean value of these variables. My code currently is as follows:
[PFUser logInWithUsernameInBackground:_usernameField.text password:_passwordField.text
block:^(PFUser *user, NSError *error) {
if (user) {
if(user.coach = @YES){
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"coach"]; //sets yes for coach value
}
if(user.club = @YES){
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"club"]; //sets yes for club
}
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AthleteLoggedIn" bundle:nil];
UISplitViewController *new = [sb instantiateInitialViewController];
self.view.window.rootViewController = new;
} else {
NSString *errorString = [error userInfo][@"error"];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Oops" message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
There are two problems with your code. The first being that you're using the assignment operator =
, and the second is that you're using dot notation for a Parse object.
What you had:
if(user.coach = @YES){ /* ... */ }
if(user.club = @YES){ /* ... */ }
The correct implementation:
if([user objectForKey:@"coach"] == @YES){ /* ... */ }
if([user objectForKey:@"club"] == @YES){ /* ... */ }
Which can be reduced to:
if([user objectForKey:@"coach"]){ /* ... */ }
if([user objectForKey:@"club"]){ /* ... */ }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.