I am working with MapKit and want to be able to add a (NSString *)itemTag value to each of my annotations. I have created myAnnotiation.m and myAnnotation.h
I tried adding itemTag to the myAnnotation.h/m but when I try to access currentAnnotation.itemTag within my main code, it says “itemID not found in protocols” – so I went to the MapKit.Framework and into MKAnnotation.h. I added (NSString *)itemID, but when I save the .h file in the Framework, it changes the file’s icon and doesn’t appear to by jiving with everything else.
Any help or links to help would be greatly appreciated. I am not even sure if I’m on the right path here, but Googling “modify iphone sdk framework” does not turn up much.
Why are you trying to modify the framework? You should be defining
itemIDas a property or instance variable (or both) inmyAnnotation.h. You say thatcurrentAnnotation.itemTagdidn’t work; for that to work, you need to have
itemTagdefined as a property of whatever classcurrentAnnotationbelongs to.Changing the header file for the framework won’t recompile it, so you won’t be able to get that to work.
EDIT: Here’s an example.
In
MyAnnotation.h:In
MyAnnotation.m:The
@propertycall defines the property and the@synthesizecall will create setters and getters for you (methods to set and retrieve the value ofitemID). InMyAnnotation.m, you can useself.itemIDor[self itemID]to get the value ofitemID, and you can useself.itemID = @"something"or[self setItemID:@"Something"]to set the value.EDIT 2:
When you get
currentAnnotation, if the compiler doesn’t know that the annotation is an instance of your MyAnnotation class, it won’t know aboutitemID. So, first ensure that you’ve included this line at the beginning of your.mfile:That wil ensure that the compiler knows about the class. When you use
currentAnnotation, you cast it as an instance ofMyAnnotationlike so:That should quiet down the warnings.