iosswiftkey-value-observing

"This class is not key value coding-compliant for the key" error in Swift


I have been getting this error message in Swift:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Faceit.ViewController 0x7f8f72501e40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key faceview.'

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var faceView: FaceView! {
        didSet{
            updateUI()
        }
    }

    var expression = FacialExpression(eyes: .closed, mouth: .frown) {
        didSet {
            updateUI()
        }
    }

    private func updateUI() {
        switch expression.eyes {
        case .open:
            faceView?.eyesOpen = true
        case .closed:
            faceView?.eyesOpen = false
        case .squinting:
            faceView?.eyesOpen = false
        }
        faceView?.mouthCurvature = mouthCurvatures[expression.mouth] ?? 0.0
    }

    private let mouthCurvatures = [FacialExpression.Mouth.grin:0.5,.frown: -1.0,.smile:1.0,.neutral:0.0,.smirk:-0.5]

}

Solution

  • See: Thread 1: signal SIGABRT Xcode 6.1

    You have to go into Interface Builder and look for the one (or more) outlets that have a warning triangle (follow the link for a screenshot). Once you delete those bad connections, you're either (1) ready to go because you have already connected your new objects or (2) you need to make the new connections so that you have all the elements loaded properly and you have no warning triangles.