• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Array annotation strangeness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Array annotation strangeness


  • Subject: Re: Array annotation strangeness
  • From: glenn andreas <email@hidden>
  • Date: Wed, 09 May 2012 13:45:43 -0500

On May 9, 2012, at 1:09 PM, Alex Zavatone wrote:

> Back on iterating through a mapKit annotation array, I'm bending my brain cell on this one.
>
> All my annotations are instances of the MyLocation class
>
> I added a method to expose the properties I want to save by returning a dict to the class.
>
> After all annotations are added, and I want to walk the array and build an array of annotations, I do this:
>
> - (IBAction)saveData:(id)sender
> {
> 		for (NSDictionary * myAnnotation in self.mapView.annotations)
> 		{
> 			MyLocation *tempLocation = [[MyLocation alloc] init ];
>
> 		//	test that the methods in the MyLocation objects actually work on an empty object
> 			NSString *myString = [tempLocation name];
> 			NSDictionary *myDict = [tempLocation returnCoordinatesInDict];
> 			NSDictionary *myStuffDict = [tempLocation returnPropertiesInDict];
> 		//	Try it with one of the MyLocation objects in the annotation array
> 			NSDictionary *myGoodsDict = [myAnnotation returnPropertiesInDict];
>
> Xcode will not let the last line compile with a "Receiver type 'NSDictionary' for instance message does not declare a method with selector 'returnPropertiesInDict'
>
> But if I comment out that line, set a breakpoint, it clearly shows that myAnnotation is a myLocation instance just like tempLocation.
>
> Does anyone know what I am missing here?


You lied to the compiler.

You told it that myAnnotation was an NSDictionary:
> for (NSDictionary * myAnnotation in self.mapView.annotations)

even though you knew it was suppose to be a MyLocation (and so it rightly protested when you tried do [myAnnotation returnPropertiesInDict] since NSDictionary doesn't implement returnPropertiesInDict.

Try:
for (MyLocation * myAnnotation in self.mapView.annotations)




Glenn Andreas                      email@hidden
The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Array annotation strangeness (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: self.myTextField.stringValue = @"" fails
  • Next by Date: Re: Array annotation strangeness
  • Previous by thread: Re: Array annotation strangeness
  • Next by thread: Re: Array annotation strangeness
  • Index(es):
    • Date
    • Thread