2011-08-16 3 views
0

J'utilise ce codeerreur « initialisation invalide » lors de la compilation

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    // Override point for customization after application launch. 

    [self.window makeKeyAndVisible]; 

    // position is a number between 0 and 1, where 0 gives the start position, and 1 gives the end position 

    CLLocationCoordinate2D startPoint = CLLocationCoordinate2DMake(37.9,-122.5); 
    CLLocationCoordinate2D endPoint = CLLocationCoordinate2DMake(37.188022,-122.39979); 

    for (int i = 1; i < 5; i++) { 
     float position = i/5.0; 
    CLLocationCoordinate2D middlePosition = [self pointBetweenStartPoint:startPoint endPoint:endPoint position:position]; 
    NSLog("%f, %f", middlePosition.latitude, middlePosition.longitude); 
    } 

    return YES; 
} 

- (CLLocationCoordinate2D)pointBetweenStartPoint:(CLLocationCoordinate2D)startPoint endPoint:(CLLocationCoordinate2D)endPoint position:(float)position { 

    CLLocationDegrees latSpan = endPoint.latitude - startPoint.latitude; 
    CLLocationDegrees longSpan = endPoint.longitude - startPoint.longitude; 

    CLLocationCoordinate2D ret = CLLocationCoordinate2DMake(startPoint.latitude + latSpan*position, 
startPoint.longitude + longSpan*position); 
    return ret; 
} 

et obtenir cette erreur: initialisation invalide dans cette ligne

CLLocationCoordinate2D middlePosition = [self pointBetweenStartPoint:startPoint endPoint:endPoint position:position];

Comment enlever?

Répondre

2

Existe-t-il une déclaration avant de pointBetweenStartPoint:endPoint:position: visible (par exemple à partir d'un fichier d'en-tête importé) avant le bloc de code que vous avez cité? Si ce n'est pas le cas, le compilateur supposera que la méthode renvoie id, ce qui n'est pas valide pour l'initialisation d'une struct CLLocationCoordinate2D, et donnez cette erreur.

Questions connexes