4
votes

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]

}
3
I have been frustrated for a long time, want to save it ASAP!XIAOLONG LI
The error message is pretty clear. Swift is case sensitive : faceview vs faceViewvadian
@vadian wow... no way! that is simple.XIAOLONG LI
@vadian I tried to change to faveview, it is still not working!XIAOLONG LI
faveview (with v) is still worse ;-) Only changing the name is not sufficient. You have to disconnect the dead connection in Interface Builder and connect the proper one.vadian

3 Answers

6
votes

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.

0
votes

Open your storyboard > Select the ViewController which class is showing error> Just remove all of the outlet> And reassign outlet. Hope your problem will be fixed. This is not a big issue , by mistake you have multiple key or different name key for one outlet and specially its faceview.

0
votes

@vadian has told me how to fix the issue. It worked, changed to faceview, also reconnect with Interface Builder. (This is important)!