How can I optimize this switch statement on a property key, ideally utilizing KVC to set @NSManaged properties

Currently the code looks pretty gross:

@NSManaged var property1: NSNumber?
@NSManaged var property2: String?
@NSManaged var property3: NSNumber
@NSManaged var property4: NSNumber?
@NSManaged var property5: Date?

override func setValue(_ value: Any?, ofProperty property: String) -> Bool {
    let undoManager = NSDocumentController.shared().currentDocument?.undoManager
    if property == "property1" {
        undoManager?.registerUndo(withTarget:self, handler: { [oldValue = self.property1] (Node) -> () in
            self.property1 = oldValue
        })
    } else if property == "property2" {
        undoManager?.registerUndo(withTarget:self, handler: { [oldValue = self.property2] (Node) -> () in
            self.property2 = oldValue
        })
    } else if property == "property3" {
        undoManager?.registerUndo(withTarget:self, handler: { [oldValue = self.property3] (Node) -> () in
            self.property3 = oldValue
        })
    } else if property == "property4" {
        undoManager?.registerUndo(withTarget:self, handler: { [oldValue = self.property4] (Node) -> () in
            self.property4 = oldValue
        })
    } else if property == "property5" {
        undoManager?.registerUndo(withTarget:self, handler: { [oldValue = self.property5] (Node) -> () in
            self.property5 = oldValue
        })
    }

The immediate thought for optimization would be utilizing KVC, setValue:forKey:, which would remove my switch statement (I know here it's a big if/else if block)

However, doing this throws an error at runtime:

[General] [ valueForUndefinedKey:]: this class is not key value coding-compliant for the key channels.

I have seen this before, and I think it's because my properties are @NSManaged, and aren't backed by an ivar. Though I am not certain

So has anybody seen this before, or know of a way I could optimize this? I only ask because there are actually upwards of 20 properties, and it feels really bad to do this