I just upgraded to the new Xcode 4.2 and am having problems with loading map annotations from my plist. I need to have the plist on a URL to update regularly.
I had no problems with the older version of Xcode, but am now getting a ARC error and
Receiver type ‘MapAnnotations’ for instance message does not declare a method with selector ‘initWithDictionary’.
Any help is greatly appreciated. Thank you in advance.
MapAnnotations.m code
-(id)initWithDictionary:(NSDictionary *)dict {
self = [super init];
if (self!=nil) {
coordinate.latitude = [[dict objectForKey:@"latitude"] doubleValue];
coordinate.longitude = [[dict objectForKey:@"longitude"] doubleValue];
self.title = [dict objectForKey:@"name"];
self.subtitle = [dict objectForKey:@"subtitle"];
self.pin = [dict objectForKey:@"pin"];
}
return self;
}
section in Mapview.M
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Locations" ofType:@"plist"];
NSArray *array = [[NSArray alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.MyPlist.plist"]];
if (array) {
NSDictionary* myDict = [NSMutableDictionary dictionaryWithCapacity:[array count]];
for (NSDictionary* dict in array) {
MapAnnotations* annotation = [[MapAnnotations alloc]iniWithDictionary:dict];
[mapview addAnnotation:annotation];
}
NSLog(@"The count: %i", [myDict count]);
}
else {
NSLog(@"Plist does not exist");
}
This error:
means the
initWithDictionarymethod hasn’t been declared inMapAnnotations.h. In the older Xcode, I think this only resulted in a warning.In
MapAnnotations.h, declare the method:By the way, I assume this line is just a typo in your question:
It should say
initWithDictionary(notiniWithDictionary).