Question

Hi I am using GoogleMaps in my ios app and there is a part where I have to save the map marker positions in the CoreData. I am using the code

GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.map = _mapView;
[waypoints_ addObject:marker];
NSDictionary *routeDict = [[NSDictionary alloc] initWithObjectsAndKeys:
                           waypoints_ ?: [NSNull null], routeName,
                           nil];
id delegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = [delegate managedObjectContext];
NSManagedObjectContext *context = [self managedObjectContext];
Route *routeInfo = [NSEntityDescription
                      insertNewObjectForEntityForName:@"Route"
                      inManagedObjectContext:context];
routeInfo.routeName = routeName;
routeInfo.wayPoints = routeDict;

But the app crashes while saving to the core data. I get the exception

-[GMSMarker encodeWithCoder:]: unrecognized selector sent to instance 0xac72940
2014-05-14 12:31:50.053 Routes[4087:a0b] *** -[NSKeyedArchiver dealloc]: warning:      NSKeyedArchiver deallocated without having had -finishEncoding called on it.
2014-05-14 12:31:50.057 Routes[4087:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GMSMarker encodeWithCoder:]: unrecognized selector sent to instance 0xac72940'
Was it helpful?

Solution

GMSMarker does not respond to encodeWithCoder:, so you can't put it into a dictionary that will then be encoded (which is what happens when you set a dictionary as an attribute in core data).

You should just be storing the underlying data waypoints in core data and then rebuilding the UI from that when requested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top