views:

828

answers:

3

When I call this function, it seems to return a pointer instead of an int. When I try and NSLog the return value, I get a warning "passing argument 1 of NSLog from incompatible pointer type." And if the NSLog runs, it crashes.

Does this have to do with this being a static method? How can I get back a real int?

I am using SDK 3.0

Here is the function in question:

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

Here is the .h code:

#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

Here is the beginning of the .m code:

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

@implementation AnnasMath

...

I am using it as follows:

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);
+7  A: 

Notice that it says "argument 1" — whereas the variable you're looking at is argument 2. You're passing a C string as the first argument of NSLog rather than an NSString (which is written like @"something" rather than just "something").

Chuck
+1  A: 

The correct string is:

NSLog(@"About to set the zoom to %i", zoom);
Jordan
+1  A: 

I have a feeling you function is returning an int as you wish.

The compile warning you are recieving is actually the string argument to NSLog... it expects an Objective-C String, and you are passing it a Cstring.

add a @ before the string and all should be well.

Akusete