草庐IT

ios - Swift 中的 "This class is not key value coding-compliant for the key"错误

coder 2023-09-14 原文

我在 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]

}

最佳答案

参见:Thread 1: signal SIGABRT Xcode 6.1

您必须进入 Interface Builder 并寻找一个(或多个)带有警告三角形的 socket (点击链接获取屏幕截图)。一旦你删除了那些坏的连接,你要么(1)准备好了,因为你已经连接了你的新对象,要么(2)你需要建立新的连接,这样你就可以正确加载所有元素并且你没有警告三角形。

关于ios - Swift 中的 "This class is not key value coding-compliant for the key"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45032697/

有关ios - Swift 中的 "This class is not key value coding-compliant for the key"错误的更多相关文章

随机推荐