Whereami Error


#1

Hi all, I have typed in the code for the Whereami app, not fully understanding it but i continued like the book advised, repetition is one of the best ways to learn. Once i have all the code written i’m getting an error message "Invalid argument type ‘void’ to unary expression

here is my full code:

#import "WhereamiViewController.h"

@implementation WhereamiViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
        // Create location manager object
        locationManager = [[CLLocationManager alloc] init];
        
        // There will be a warning from this line of code; ignore it for now
        [locationManager setDelegate:self];
        
        // And we want it to be as accurate as possible
        // regardless of how much time/power it takes
        [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
        
        // Tell our manager to start looking for its location immediately
        [locationManager startUpdatingLocation];
    }
    
   - (void)locationManager:(CLLocationManager *)manager
         didUpdateToLocation:(CLLocation *)newLocation
                fromLocation:(CLLocation *)oldLocation
       {
           NSLog(@"%@", newLocation)
       }
       
       - (void)locationManager:(CLLocationManager *)manager
          didFailWithError:(NSError *)error
    {
        NSLog(@"Could not find location %@", error);
    }
    return self;
}

@end

Here is where the error message appears, the very first line

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"%@", newLocation) }

I’m using Xcode 4.5.2 also if this helps any, any advice would be much appreciated


#2

You have entered two extra lines:

#import "WhereamiViewController.h"

@implementation WhereamiViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
        // Create location manager object
        locationManager = [[CLLocationManager alloc] init];
        
        // There will be a warning from this line of code; ignore it for now
        [locationManager setDelegate:self];
        
        // And we want it to be as accurate as possible
        // regardless of how much time/power it takes
        [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
        
        // Tell our manager to start looking for its location immediately
        [locationManager startUpdatingLocation];
}
    
- (void)locationManager:(CLLocationManager *)manager
         didUpdateToLocation:(CLLocation *)newLocation
                fromLocation:(CLLocation *)oldLocation
{
           NSLog(@"%@", newLocation)
}
       
- (void)locationManager:(CLLocationManager *)manager
          didFailWithError:(NSError *)error
{
        NSLog(@"Could not find location %@", error);
}
    return self;  <--- remove this line
}   <-- remove this line
@end

Remove the last two lines (marked <— …) before the @end.

It’s sad that Xcode is emitting such an uninformative message. You should summit a usability-bug report.


#3

Wow many thanks for helping me with this. Yes the Xcode error message was absolutely useless in helping me solve my problem but thanks to you I got it working :smiley:

Many Thanks