Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode doesn't give warning for unreachable code

I have accidentally written a code after the return statement which can't be reach by any code path. I was surprised to get no warning from Xcode for last line.
How do I get Xcode to show this?

-(int) hits{
    static int hits = 0;
    hits++;

    NSLog(@"Good Code");
    return hits ;
    NSLog(@"Bad code");
}
like image 825
forvaidya Avatar asked Oct 28 '25 20:10

forvaidya


1 Answers

  1. Click on the main project in the project navigator.
  2. Click build settings at the top.
  3. Type "warning" in the search bar in the upper right.

You should now see a list of potential issues that the compiler will check for. You can turn warnings for all of these issues on or off and even make the compiler treat the issue as an error.

Edit:

To expand on the comments:

  1. Click on the main project in the project navigator.
  2. Click build phases at the top.
  3. Expand compile sources.
  4. Double click on the offending file.
  5. Type -Wunreachable-code in the pop-up that appears.
  6. Click off to save the compiler flag.

You should now see the particular warning you were inquiring about upon building.

like image 94
andreww741 Avatar answered Oct 31 '25 00:10

andreww741



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!