encodeWithCoder出错

时间:2014-05-14 07:17:11

标签: ios google-maps core-data google-maps-sdk-ios nscoding

您好我在我的GoogleMaps应用中使用了ios,并且我必须在CoreData中保存地图标记位置。我正在使用代码

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;

但是应用程序在保存到核心数据时崩溃了。 我得到了例外

-[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'

1 个答案:

答案 0 :(得分:1)

GMSMarker不响应encodeWithCoder:,因此您无法将其放入将被编码的字典中(当您将字典设置为核心数据中的属性时会发生这种情况)

您应该将基础数据路点存储在核心数据中,然后在请求时重建UI。