In my opinion, your application crashes due to these lines
let mapping = RKObjectMapping(forClass: self) let coordinateMapping = RKAttributeMapping(fromKeyPath: "coordinate", toKeyPath: "coordinate")
You want to map an optional property / variable, but it may be that when you call objectMapping() , your coordinate is zero.
Have you tried something like this:
import MapKit class Activity: NSObject { var coordinate: CLLocationCoordinate2D? class func objectMapping() -> RKObjectMapping { if let c = self. coordinate { let mapping = RKObjectMapping(forClass: self) let coordinateMapping = RKAttributeMapping(fromKeyPath: "coordinate", toKeyPath: "coordinate") coordinateMapping.valueTransformer = RKCLLocationCoordinate2DValueTransformer() mapping.addPropertyMapping(coordinateMapping) return mapping } return nil } }
I'm not sure if this works, but I think let mapping = RKObjectMapping(forClass: self) trying to display your entire Activity class, and this will crash your code when coordinate not set at this time.
Miralem cebic
source share