0

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...

Timothy Frisch
  • 2,995
  • 2
  • 30
  • 64
  • enclose the nested if statement, i.e. if ([self isAllFieldVerified]), with brackets and try again. – x4h1d Jul 21 '14 at 18:59

1 Answers1

2

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Thanks that worked. Why would this still compile and run on my iphone if it doesn't work on the archiver? – Timothy Frisch Jul 21 '14 at 19:02
  • 1
    As I stated at the start of my answer, the code is valid for a debug build but not a non-debug build. That's the whole point of the `#ifdef DEBUG` line. When you were testing on your iPhone you were doing a debug build but when you archive you do a distribution (non-debug) build. – rmaddy Jul 21 '14 at 19:04