Search code examples
objective-cxcodeparsingarchiveexpected-exception

Parse Issue: Expected Statement only when archiving


I get a Parse Issue Expected Statement error only when trying to archive my XCode project. I do not receive this error and the app runs fine when I regularly build it instead of archiving.

    -(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;

    if ([[[NSUserDefaults standardUserDefaults] objectForKey:SavedUsername] length] && [[[NSUserDefaults standardUserDefaults] objectForKey:SavedPassword] length]) {
        [self.btnRememberMe setSelected:YES];
        self.isButtonSelected = YES;
        self.txtFieldUsername.text = [[NSUserDefaults standardUserDefaults] objectForKey:SavedUsername];
        self.txtFieldPassword.text = [[NSUserDefaults standardUserDefaults] objectForKey:SavedPassword];

//        NSLog(@"username = %@ , pass = %@",[[NSUserDefaults standardUserDefaults] objectForKey:SavedUsername], [[NSUserDefaults standardUserDefaults] objectForKey:SavedPassword]);
        if ([self isAllFieldVerified])
            #ifdef DEBUG
                NSLog(@"all fields are verified");
            #endif
            //[self makeWebAPICallMethodCalling];
    }else {
        [self.btnRememberMe setSelected:NO];
        self.isButtonSelected = YES;
        self.txtFieldUsername.text = @"";
        self.txtFieldPassword.text = @"";
    }


}

The parser error is thrown by the else line...


Solution

  • The problem is your #ifdef for the NSLog statement. When you do a non-debug build the NSLog line isn't there leaving an if statement with no code.

    Try this:

    #ifdef DEBUG
        if ([self isAllFieldVerified])
            NSLog(@"all fields are verified");
    #endif
    

    or at least add curly braces:

        if ([self isAllFieldVerified]) {
            #ifdef DEBUG
                NSLog(@"all fields are verified");
            #endif
        }
    

    This is an example of why it's always a good idea to use curly braces, even if there is only one line.