Hi all,
What is the best way to store an MKCoordinateRegion using core data? I assume there is a way to convert this to binary data somehow??
Many thanks
Jules
Hi all,
What is the best way to store an MKCoordinateRegion using core data? I assume there is a way to convert this to binary data somehow??
Many thanks
Jules
Sorry.... I just found the transformable type in core data, I believe this should do the trick.
My suggestion is to simply store the MKCoordinateRegion's struct values (latitude, longitude, latitudeDelta, and longitudeDelta) as separate properties, and then on your model class provide a custom accessor that assembles these into a MKCoordinateRegion object.
For example:
// Snip...boilerplate CoreData code goes here...
@dynamic latitude;
@dynamic longitude;
@dynamic latitudeDelta;
@dynamic longitudeDelta;
- (MKCoordinateRegion)region {
CLLocationCoordinate2D center = {
[self.latitude floatValue],
[self.longitude floatValue]
};
MKCoordinateSpan span = {
[self.latitudeDelta floatValue],
[self.longitudeDelta floatValue]
};
return MKCoordinateRegionMake(center, span);
}
If you want to be extra clever, you can create a custom read-only property that exposes the internal data as above.