Question

I am new to Objective C and trying to make a basic map application in Xcode. I keep getting this error on (void)mapView method,

Invalid argument type 'void' to unary expression 

Here is my code,

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.mapView.delegate = self;
}

//H+ adding to have scale adjusted
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];

}

What is causing this?

Was it helpful?

Solution

You're missing the closing brace (}) on your viewDidLoad function. Corrected, it should look like this (see the line with the THIS!!! comment):

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.mapView.delegate = self;
} // <-- THIS!!!

//H+ adding to have scale adjusted
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
}

As a result of the missing brace, the compiler thinks that your mapView:didUpdateUserLocation function definition is an expression within the viewDidLoad function, not a function definition. I'm guessing that's probably not what you intended.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top