Re: Mapkit annotation arrays and writing to a file
Re: Mapkit annotation arrays and writing to a file
- Subject: Re: Mapkit annotation arrays and writing to a file
- From: Conrad Shultz <email@hidden>
- Date: Tue, 08 May 2012 14:53:55 -0700
On 5/8/12 2:35 PM, Alex Zavatone wrote:
> Well, I had a similar problem saving the information to a JSON file
> and had to rebuild the dictionary without the CLLocationCoordinate2D
> struct, before NSJSONSerialization would serialize the dictionary.
>
> The reason I think it's a struct is that's how it's defined in
> CLLocation.h and right now in the debugger, annotation is showing as
> (struct objc_object * const), which sorta conflicts with what you
> wrote (TTBOMK).
>
> Here are the details from CLLocation.h:
No one disputes that CLLocationCoordinate2D is a struct. What Jens is
saying is that you can't store an unwrapped struct in a Cocoa collection
- be it a dictionary, array, or set.
What's getting lost in translation here is that -annotations is an array
of objects of type id <MKAnnotation>.
What sort of object conforming to MKAnnotation are you adding to your
annotations array? Whatever it is, it must have a -coordinate property.
It is *this* property this is a CLLocationCoordinate2D struct. This is
how the data is getting stored in a Cocoa collection.
In any event, I don't see how you could directly serialize your
annotation object to a JSON object for exactly the reason Jens described
(i.e. type incompatibility).
If you need to convert to JSON you could, for example, write an
NSValueTransformer that converts your id <MKAnnotation> to an
NSDictionary that is compliant with NSJSONSerialization requirements.
Assuming that you are planning on using JSON to communicate with a web
service, though, you will need to determine what data structure the
service is expecting and emit that.
--
Conrad Shultz
Synthetiq Solutions
www.synthetiqsolutions.com
_______________________________________________
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