Search code examples
iosswiftparse-platformlocal-datastore

'PFObject values may not have class: NSConcreteValue'


App keeps crashing on this Method - trying to simply pin a Parse object to the local data store as outlined in the docs Parse docs:

func saveToBackground(title:String, description:String, coords:CLLocationCoordinate2D, image:UIImage, objectId:String, dateFound:String){

    let imageData = image.jpeg(.low)
    let imageFile = PFFile(name: "image.png", data: imageData!)


    let foundObject = PFObject(className: "FoundObjects")
    foundObject["title"] = title
    foundObject["description"] = description
    foundObject["coordinates"] = coords
    foundObject["image"] = imageFile
    foundObject["objectId"] = objectId
    foundObject["dateFound"] = dateFound
    foundObject.pinInBackground()

}

error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'PFObject values may not have class: NSConcreteValue'

Any ideas anyone?


Solution

  • At least one of your values is an NSConcreteValue class, which can't be stored on a PFObject. Figure out which line is causing the issue by setting a breakpoint and stepping through, and make sure to cast that value to the expected class. Or you could cast all of these to their expected class, cover your bases.

    Edit: As pointed out by MartynE23, the issue was actually the CLLocationCoordinate2D, which must be converted to a PFGeoPoint to add to a Parse Object