C if vs switch
This question already has an answer here:
You need a separate scope in the case
if you want to declare any variables there:
switch ((int)typeOfHall) {
case 1:
{ /* Introduce a scope ... */
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Game"];
NSPredicate *p = [NSPredicate predicateWithFormat:@"player_id == %@ ",[[NSUserDefaults standardUserDefaults] valueForKey:@"LoggedUserId"]];
request.predicate = p;
break;
} /* ... that ends here. */
default:
break;
}
Side note: if LocalHall
is an enum value, your code is more readable without the cast:
switch (typeOfHall) {
case LocalHall:
// ...
链接地址: http://www.djcxy.com/p/14796.html
下一篇: C如果与切换