1

I have the following function that would remove from the "Map" entity (that has 'name' as the only attribute) the specified 'mapname', in this case 'peachfarm'.

However, I get the error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key peachfarm.'

func deleteMap(_ sender: UIButton) {
    var mapname = sender.accessibilityHint
    managedObjectContext.delete(fetchedResultsControllerForMapEntity.value(forKey: mapname!) as! NSManagedObject)
}

This is weird because I definitely have a value for the above key.

shallowThought
  • 19,212
  • 9
  • 65
  • 112
huzal12
  • 79
  • 2
  • 10
  • 1
    Calling `someEntity.value(forKey: mapName)` makes no sense. You have to fetch the matching objects before you can delete them. See http://stackoverflow.com/questions/38017449/swift-3-core-data-delete-object for an example. – Martin R Apr 13 '17 at 13:02

0 Answers0