这是一个switch语句,我收到错误:
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
// show wait view here
statusLabel.text = @"Processing...";
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view and unlock iClooud Syncing
statusLabel.text = @"Done!";
NSError *error = nil;
[SFHFKeychainUtils storeUsername:@"IAPNoob01" andPassword:@"whatever" forServiceName: kStoredData updateExisting:YES error:&error];
// apply purchase action - hide lock overlay and
[oStockLock setBackgroundImage:nil forState:UIControlStateNormal];
// do other thing to enable the features
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view here
statusLabel.text = @"";
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"Error payment cancelled");
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view here
statusLabel.text = @"Purchase Error!";
break;
default:
break;
}
最后两种情况加上默认情况会给我以下错误:
无法从switch语句跳转到此案例标签
我多次使用switch语句;这是我第一次看到这个。代码已从教程(here)中复制,我正在尝试为我的应用程序进行调整。希望得到这方面的帮助。 SD
答案 0 :(得分:100)
C不是Swift。如果您使用花括号围绕所有案例内部构建switch
语句,例如this,那么您会更高兴:
switch (tag) {
case 1: { // curly braces
// ...
break;
}
case 2: { // curly braces
// ...
break;
}
case 3: { // curly braces
// ...
break;
}
}
额外的花括号允许你做一些你不能做的事情。