gpt4 book ai didi

objective-c - 是什么导致了这个 : Cannot jump from switch statement to this case label

转载 作者:IT老高 更新时间:2023-10-28 11:41:27 30 4
gpt4 key购买 nike

这是一个我收到错误的 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;
}

最后两种情况,加上默认情况,给我以下错误:

Cannot jump from switch statement to this case label

我用过很多次switch语句;这是我第一次看到这个。代码已从教程 ( here ) 中复制,我正在尝试使其适应我的应用程序。感谢您对此的帮助。标清

最佳答案

C 不是 Swift。如果您使用花括号围绕所有案例内部构造您的 switch 语句,您会更开心,例如 this :

switch (tag) {
case 1: { // curly braces
// ...
break;
}
case 2: { // curly braces
// ...
break;
}
case 3: { // curly braces
// ...
break;
}
}

额外的花括号允许你做你不能做的事情。

关于objective-c - 是什么导致了这个 : Cannot jump from switch statement to this case label,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34829955/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com