モバイルSAAS - Parseを介してログインするアプリケーションを構築しています。
ログイン要求から返される可能性のあるエラー コードは複数あります。現時点では、各エラー コードに対して if ステートメントを実行し、次のような関連するアラート ビューを表示します。
if (error == nil) {
// Something went wrong
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"LoginAlertErrorTitle", @"Login Error Alert View Title") message:NSLocalizedString(@"LoginStandardError", @"Login error message text - standard error") delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"GlobalOKButtonTitle", @"Global Ok button title"), nil];
[alertView show];
} else if ([error code] == kPFErrorObjectNotFound) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"LoginAlertErrorTitle", @"Login Error Alert View Title") message:NSLocalizedString(@"LoginErrorObjectNotFound", @"Login error message text - object not found") delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"GlobalOKButtonTitle", @"Global Ok button title"), nil];
[alertView show];
} else if ([error code] == kPFErrorConnectionFailed) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"LoginAlertErrorTitle", @"Login Error Alert View Title") message:NSLocalizedString(@"LoginAlertErrorConnection", @"Login error message text - connection failed") delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"GlobalOKButtonTitle", @"Global Ok button title"), nil];
[alertView show];
} else {
NSLog(@"A Login error occurred: %i",[error code]);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"LoginAlertErrorTitle", @"Login Error Alert View Title") message:[[error userInfo] objectForKey:@"error"] delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"GlobalOKButtonTitle", @"Global Ok button title"), nil];
[alertView show];
}
ケース/スイッチングで同じことを行うより効率的な方法はありますか?
実際のエラー コードは次のように設定されます。
/*! @abstract 100: The connection to the Parse servers failed. */
extern NSInteger const kPFErrorConnectionFailed;
これにより、ケースステートメントでこれをセットアップできると思います。これはこれにアプローチするための正しい/最良の方法でしょうか? handleErrorAlert:
おそらく別の方法である必要がありますか?
上記の例でこのスイッチをどのようにコーディングしますか?