1
votes

I have this C method:

.h

NSString *NSStringFromMKMapPoint(MKMapPoint mapPoint);

.m

NSString *NSStringFromMKMapPoint(MKMapPoint mapPoint) {
    return [NSString stringWithFormat:@"%i,%i", (int)mapPoint.x, (int)mapPoint.y];
}

Trying to set an NSString using the return value, as so:

NSString *tilePointString = NSStringFromMKMapPoint(tilePoint);

is giving me this error:

Implicit conversion of 'int' to 'NSString *' is disallowed with ARC

1
Show how this function (not method) is called.rmaddy
Exactly which line is giving you the error?rmaddy
Also, is the function and the caller in two different files? If so, is the function declared in some .h file? Does the declaration have the same signature as the implementation?rmaddy
Yes. Declared in a .h file, implemented in a .m file, with the same signature.Andrew
And properly included where you use it? It really smells like a default return type issue.s.bandara

1 Answers

1
votes

It sounds like you've failed to #include or #import the header file that declares the method in the file in which you're calling it. Without a function declaration, C (and presumably Objective-C) will default to int as the return type. That would explain your error on this line:

NSString *tilePointString = NSStringFromMKMapPoint(tilePoint);

I think the compiler here is assuming a return type of int, and then complaining that it can't convert int to NSString* in the assignment.

So, check the file(s) where you're calling this function and make sure that you've imported the header file that declares the function.