vendredi 26 août 2016

iOS if vs switch

I can't understand why this works with if statement and not switch:

if ((int)typeOfHall == 1) {//LocalHall
    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Game"];
    NSPredicate *p = [NSPredicate predicateWithFormat:@"player_id == %@ ",[[NSUserDefaults standardUserDefaults] valueForKey:@"LoggedUserId"]];
    request.predicate = p;
}

The code bellow it will not work (Error: Expected expression (on NSFetchRequest)):

switch ((int)typeOfHall) {
    case 1:
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Game"]; //Error Expected expression
        NSPredicate *p = [NSPredicate predicateWithFormat:@"player_id == %@ ",[[NSUserDefaults standardUserDefaults] valueForKey:@"LoggedUserId"]];
        request.predicate = p;
        break;
    default:
        break;             
}

I don't know why this happens. I suppose that switch and if statements are similar, but in this case it seems that are very different.

Do you have any clue why this happens?

Aucun commentaire:

Enregistrer un commentaire