[英]Parse.com current user if statement
我將Parse用作應用程序的移動后端。 我在我的“用戶”數據表(用戶類別)中的“教練”和“俱樂部”中添加了2個布爾值列,基本上說明了他們是教練還是俱樂部。 登錄期間需要根據這些變量的布爾值執行if語句。 我的代碼當前如下:
[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];
}
}];
您的代碼有兩個問題。 第一個是使用賦值運算符=
,第二個是對解析對象使用點表示法。
您所擁有的:
if(user.coach = @YES){ /* ... */ }
if(user.club = @YES){ /* ... */ }
正確的實現:
if([user objectForKey:@"coach"] == @YES){ /* ... */ }
if([user objectForKey:@"club"] == @YES){ /* ... */ }
可以簡化為:
if([user objectForKey:@"coach"]){ /* ... */ }
if([user objectForKey:@"club"]){ /* ... */ }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.