0

I'm a newbie in Objective-C, and I'm trying to add Markers to a mapView in my Apple app.

In my class Map, I'm trying to add a function wich adds markers.

In Map.h I add:

- (void)setMarkers:(MKMapView *)mv;

And in Map.m:

- (void)setMarkers:(MKMapView *)mv
{

CLLocationCoordinate2D newCoord = { 38.989567, -1.856283};
MapPoint *mp = [[MapPoint alloc] initWithCoordinate:newCoord title:[NSString stringWithFormat:@"Azam Home"] subTitle:@"Home Sweet Home"];
[mv addAnnotation:mp];

}

But when I try to call this function:

[setMarkers mv:map];

I have this error:

Map.m:278:6: Use of undeclared identifier 'setMarkers'

What am I missing?

Thank you in advance.

1 Answer 1

3

You are missing self:

[self setMarkers:mv];
Sign up to request clarification or add additional context in comments.

6 Comments

It also works changing - to + and [Map setMarkers:mv] Thanks!
Changing - to + makes the method static, but if that works, that's fine. :)
@SuneTrudslev There are no static methods in Objective-C. Methods declared with a + are class methods, not static methods.
What is the difference, in your opinion, between static and class method?
Nitpickers will object to the term "static" for class methods in Objective-C, but at the 10,000 foot level (or even the 10 foot level) they're the same. On close examination there are distinctions in that a class method is still a dynamic method, only one "sent" to the class object rather than a class instance. "Static", on the other hand, basically represents a "hard coded" linkage where the address of the method is effectively stored in the calling instruction.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.