DCJones
DCJones

Reputation: 3461

Xcode compilation error "Control reaches end of non-void function"

I have an error in a script I am writing, the error is:

Control reaches end of non-void function

This is my code:

-(BOOL) hasInternet {
    Reachability *reach = [Reachability reachabilityWithHostName:@"www.google.co.uk"];
    NetworkStatus internetStats = [reach currentReachabilityStatus];

    if (internetStats == NotReachable){
        UIAlertView *alertOne = [[UIAlertView alloc] initWithTitle:@"Internet" message:@"is DOWN" delegate:self cancelButtonTitle:@"Turn on your Internet" otherButtonTitles:@"Cancel",nil];
        [alertOne show];
    }
}

Can anyone see where I have gone wrong?

Upvotes: 0

Views: 383

Answers (1)

fredpi
fredpi

Reputation: 8952

Your method is designed to return a boolean value using a return statement, for example return YES;.

Since you haven't implemented such thing, the method won't compile successfully. If you want to return a BOOL you can add a return statement. If you don't want to return a BOOL just change the method initialization:

    -(void) hasInternet {

       Reachability *reach = [Reachability reachabilityWithHostName:@"www.google.co.uk"];
       NetworkStatus internetStats = [reach currentReachabilityStatus];

      if (internetStats == NotReachable){
         UIAlertView *alertOne = [[UIAlertView alloc] initWithTitle:@"Internet" message:@"is DOWN" delegate:self cancelButtonTitle:@"Turn on your Internet" otherButtonTitles:@"Cancel",nil];
         [alertOne show];
      }

    }

Upvotes: 1

Related Questions