如何解决在switch语句中的NSString预期的expression式错误?

我在下面的这个NSString的代码的第一行的switch语句中得到了“expected expression”错误: NSString *emailTitle = @"some text";

 break; case 4: // mail // Email Subject NSString *emailTitle = @"some text"; // Email Content NSString *messageBody = @"http://www.example.com/"; // To address NSArray *toRecipents = [NSArray arrayWithObject:@""]; MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; mc.mailComposeDelegate = self; [mc setSubject:emailTitle]; [mc setMessageBody:messageBody isHTML:NO]; [mc setToRecipients:toRecipents]; // Present mail view controller on screen [self presentViewController:mc animated:YES completion:NULL]; break; case 5: 

没有这个电子邮件代码的switch语句工作正常。

谢谢你的帮助

您不能在case语句中声明一个variables,因为范围是不明确的…

更改为下面的范围由括号{}指定

  case 4: { // mail // Email Subject NSString *emailTitle = @"some text"; // Email Content NSString *messageBody = @"http://www.example.com/"; // To address NSArray *toRecipents = [NSArray arrayWithObject:@""]; MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; mc.mailComposeDelegate = self; [mc setSubject:emailTitle]; [mc setMessageBody:messageBody isHTML:NO]; [mc setToRecipients:toRecipents]; // Present mail view controller on screen [self presentViewController:mc animated:YES completion:NULL]; } break; case 5: