For the second part, the reason for the warning is that you assign plain integer to NSInteger pointer. NSInteger
is of a type int
or long
So you are doing (incorrectly):
NSInteger * tag = 2;
EDIT:
This is how you could use NSInteger:
NSInteger myi = 42;
NSLog(@"int: %d", myi);
NSInteger * i = &myi; // i is a pointer to integer here
*i = 43; // dereference the pointer to change
// the value at that address in memory
NSLog(@"int: %d", myi);
Given above, you are trying:
NSInteger * i = &myi;
i = 2; // INCORRECT: i is an pointer to integer
Declare tag
as NSInteger
instead of NSInteger*
and use assign
in property (I'd give you exact code but I'm on linux atm ...).
END OF EDIT
For the first part I'm not sure how is the object of X
being passed to your method, but you should be then able to do [yourobject tag]
if the tag
method is part of the interface that the method is using to get data from object X
.
What I mean is that the MKAnnotation
protocol does not have tag
property so you have to typecast the object to your type of object e.g. X *anX = (X*)self.annotation;
,or wherever the annotation
object comes from, then you should be able to access tag, [anX tag]
- if that is the your X
object
I've found this example code in Apple docs that uses custom annotation.
In the example the annotation is set on view.
When view is drawn it uses data from the object that implements annotation protocol. The object is typecasted to the actual object before values are accessed (see drawing method of the view).
You can see in the controller how new annotations are set in regionDidChangeAnimated
on the view.