views:

135

answers:

1

Hi

I'm trying to iterate over a collection of objects and create an annotation for each object as seen in this code, but at the closing } of the for loop i get this error Selector element does not have valid object type. What does this mean?

    for (POI myPOI in appDelegate.pois){
     CLLocationCoordinate2D location;
     location.latitude=[myPOI.lat doubleValue];
     location.longitude=[myPOI.lon doubleValue];
     region.span=span;
     region.center=location;

     LocationAnnotation *locAnn;

     locAnn = [[LocationAnnotation alloc] initWithCoordinate:location];
     [mapView addAnnotation:locAnn];
     [mapView setRegion:region animated:YES];

     [locAnn release];
    }

Also i get Variable sized object cannot be initialized at the beginning of the loop. And, instance variable lat (and lon too) is declared protected.

What have i done wrong?
Thanks

+1  A: 

Is "POI" an object? If so, you're not declaring "myPOI" as a pointer to a POI. You'll want:

POI * myPOI ...

If POI is not an object, you can't use fast enumeration.

Joshua Nozzi
When i make it an object, i get rid of the other errors, but now have a new one - `Expression does not have a valid object type`. What does this mean? Do i have to make my POI class conform to the NSFastEnumeration protocol or some such?
joec
You'll need to provide a lot more information. What does the "pois" property of your app delegate return? Where is this new error being thrown? What is the POI class and what do "lat" and "long" return (object or primitive)?I haven't seen that particular error before, but I do know the collection object must conform to the fast enumeration protocol (but not the objects in the collection).
Joshua Nozzi
I solved this problem - my appDelegate wasnt getting instantiated correcty. Once i sorted that, the error went away - thanks for the help.
joec