2009-08-13 5 views
1

Lorsque j'appelle cette fonction, il semble retourner un pointeur au lieu d'un int. Quand j'essaye et NSLog la valeur de retour, j'obtiens un avertissement "passant l'argument 1 de NSLog du type de pointeur incompatible." Et si le NSLog s'exécute, il se bloque.Pourquoi cette fonction renvoie-t-elle un pointeur?

Est-ce que cela a à voir avec cette méthode statique? Comment puis-je récupérer un vrai int?

J'utilise SDK 3.0

Voici la fonction en question:

+(int) getZoomFromExtent: (CLLocationCoordinate2D)bottomLeft 
      withTopRight:(CLLocationCoordinate2D)topRight 
      withPixelsX:(int)pixelsX 
      withPixelsY:(int)pixelsY 
     withMapContents: (RMMapContents*) contents; 

Voici le code .h:

#import <Foundation/Foundation.h> 
#import <math.h> 
#import <CoreLocation/CLLocation.h> 
#import "RMTile.h" 
#import "RMMapContents.h" 

@interface AnnasMath : NSObject {} 

+(CLLocationCoordinate2D) normalizePixelCoords:(CLLocationCoordinate2D) point; 
+(RMTile)tileWithCoordinate:(CLLocationCoordinate2D)point andZoom:(int)zoom; 
+(NSArray *)getTileArrayWithUpperLeft:(CLLocationCoordinate2D)upperLeft andLowerRight: (CLLocationCoordinate2D)lowerRight fromZoom:(int)bottomZoom toZoom:(int)topZoom; 
+(int)getTileCountWithUpperLeft:(CLLocationCoordinate2D)upperLeft andLowerRight:(CLLocationCoordinate2D)lowerRight fromZoom:(int)bottomZoom toZoom:(int)topZoom; 
+(int) getZoomFromExtent: (CLLocationCoordinate2D)bottomLeft 
      withTopRight: (CLLocationCoordinate2D)topRight 
       withPixelsX:(int)pixelsX 
       withPixelsY:(int)pixelsY 
      withMapContents: (RMMapContents*) contents; 

@end

Voici la début du code .m:

#import "AnnasMath.h" 
#import <Foundation/Foundation.h> 
#import <math.h> 
#import "TileWrapper.h" 

@implementation AnnasMath 

... 

Je l'utilise comme suit:

int zoom = [AnnasMath getZoomFromExtent:[[extent objectForKey:@"bottomLeft"]coordinate] 
       withTopRight:[[extent objectForKey:@"topRight"]coordinate] 
          withPixelsX:300 
          withPixelsY:300 
         withMapContents:t.mapVC.mapView.contents]; 

NSLog("About to set the zoom to %i", zoom); 

Répondre

10

Notez qu'il dit « argument 1 » - alors que la variable que vous regardez est l'argument 2. Vous passez une chaîne C comme premier argument de NSLog plutôt qu'un NSString (qui est écrit comme @"something" plutôt que simplement "something").

1

La chaîne correcte est:

NSLog(@"About to set the zoom to %i", zoom); 
1

J'ai le sentiment que la fonction est un int retournais que vous le souhaitez. L'avertissement de compilation que vous recevez est en réalité l'argument de chaîne de NSLog ... il attend une chaîne Objective-C, et vous lui passez une Cstring.

ajouter un @ avant la chaîne et tout devrait bien se passer.

Questions connexes