2017-07-11 24 views
0

私は、このエラーメッセージを取得されています:「このクラスは、キー値コーディング準拠のキーのためではありません」というエラー

がキャッチされない例外により「NSUnknownKeyException」にアプリを終了、理由:'[<Faceit.ViewController 0x7f8f72501e40> setValue:forUndefinedKey:]:このクラスはキーではありませんキーフェイスビューのコーディングに準拠した価値があります。

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] 

} 

import Foundation 

struct FacialExpression 
{ 
    enum Eyes: Int { 
     case open 
     case closed 
     case squinting 

    } 

    enum Mouth: Int { 
     case frown 
     case smirk 
     case neutral 
     case grin 
     case smile 

     var sadder: Mouth { 
      return Mouth(rawValue: rawValue - 1) ?? .frown 
     } 
     var happier: Mouth{ 
      return Mouth(rawValue: rawValue + 1) ?? .smile 
     } 
    } 

    var sadder: FacialExpression { 
     return FacialExpression(eyes: self.eyes, mouth: self.mouth.sadder) 
    } 

    var happier: FacialExpression { 
     return FacialExpression(eyes: self.eyes, mouth: self.mouth.happier) 
    } 

    let eyes: Eyes 
    let mouth: Mouth 
} 

import UIKit 

@IBDesignable 
class FaceView: UIView { 
    @IBInspectable 
    var scale: CGFloat = 0.9 

    @IBInspectable 
    var eyesOpen: Bool = true 

    @IBInspectable 
    var lineWidth: CGFloat = 5.0 

    @IBInspectable 
    var mouthCurvature: Double = -0.5 

    @IBInspectable 
    var color: UIColor = UIColor.blue 

    private var skullRadius : CGFloat { 
     return min(bounds.size.width,bounds.size.height)/2 * scale 
    } 
    private var skullCenter: CGPoint{ 
     return CGPoint(x: bounds.midX, y: bounds.midY) 
    } 

    private enum Eye{ 
     case left 
     case right 
    } 
    private func pathForEye(_ eye:Eye) ->UIBezierPath{ 

     func centerForEye(_ eye: Eye) ->CGPoint{ 
      let eyeOffset = skullRadius/Ratios.skullRadiusToEyeOffset 
      var eyeCenter = skullCenter 
      eyeCenter.y -= eyeOffset 
      eyeCenter.x += ((eye == .left) ? -1 : 1)*eyeOffset 
      return eyeCenter 
     } 

     let eyeRadius = skullRadius/Ratios.skullRadiusToEyeRadius 
     let eyeCenter = centerForEye(eye) 

     let path : UIBezierPath 
     if eyesOpen{ 
      path = UIBezierPath(arcCenter: eyeCenter, radius: eyeRadius, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: true) 

     } else { 
      path = UIBezierPath() 
      path.move(to: CGPoint(x: eyeCenter.x - eyeRadius, y: eyeCenter.y)) 
      path.addLine(to: CGPoint(x: eyeCenter.x + eyeRadius, y: eyeCenter.y)) 
     } 

     path.lineWidth = lineWidth 
     return path 
    } 

    private func pathForMouth() ->UIBezierPath{ 
     let mouthWidth = skullRadius/Ratios.skullRadiusToMouthWidth 
     let mouthHeight = skullRadius/Ratios.skullRadiusToMouthHeight 
     let mouthOffset = skullRadius/Ratios.skullRadiusToMouthOffset 

     let mouthRect = CGRect(
      x: skullCenter.x - mouthWidth/2, 
      y: skullCenter.y + mouthOffset, 
      width : mouthWidth, 
      height : mouthHeight 
     ) 

     let smileOffset = CGFloat(max(-1,min(mouthCurvature,1)))*mouthRect.height 
     let start = CGPoint(x: mouthRect.minX, y: mouthRect.midY) 
     let end = CGPoint(x: mouthRect.maxX, y: mouthRect.midY) 

     let cp1 = CGPoint(x: start.x + mouthRect.width/3, y: start.y + smileOffset) 
     let cp2 = CGPoint(x: end.x - mouthRect.width/3, y: start.y + smileOffset) 
     let path = UIBezierPath() 
     path.move(to: start) 
     path.addCurve(to: end, controlPoint1: cp1, controlPoint2: cp2) 

     path.lineWidth = lineWidth 
     return path 
    } 

    private func pathForSkull() ->UIBezierPath{ 
     let path = UIBezierPath(arcCenter: skullCenter, radius: skullRadius, startAngle: 0, endAngle: 2 * CGFloat.pi, clockwise: false) 
     path.lineWidth = 5.0 
     return path 
    } 

    override func draw(_ rect: CGRect) { 
     color.set() 
     pathForSkull().stroke() 
     pathForEye(.left).stroke() 
     pathForEye(.right).stroke() 
     pathForMouth().stroke() 
    } 

    private struct Ratios{ 
     static let skullRadiusToEyeOffset: CGFloat = 3 
     static let skullRadiusToEyeRadius: CGFloat = 10 
     static let skullRadiusToMouthWidth: CGFloat = 1 
     static let skullRadiusToMouthHeight: CGFloat = 3 
     static let skullRadiusToMouthOffset: CGFloat = 3 
    } 

} 
+0

私は長い間不満を感じており、早急にそれを保存したい! –

+2

エラーメッセージはかなり明確です。スウィフトは大文字と小文字を区別します: 'faceview'対' faceView' – vadian

+0

@vadianうわー...まさか!それは簡単です。 –

答えて

1

@vadianは問題を解決する方法を教えてくれました。それはFaceviewに変更し、Interface Builderにも再接続しました。 (これは重要)!

0

参照:Thread 1: signal SIGABRT Xcode 6.1

あなたがInterface Builderのに行くと1つ(またはそれ以上)の警告の三角形を(スクリーンショットへのリンクをたどる)持ってコンセントを探す必要があります。これらの不良接続を削除すると、(1)新しいオブジェクトをすでに接続しているために移動する準備ができているか、または(2)すべての要素が正しくロードされ、警告が表示されないように新しい接続を作成する必要があります三角形。

0

ストーリーボードを開く>どのクラスがエラーを表示しているViewControllerを選択する>コンセントをすべて削除する>コンセントを再割り当てします。 あなたの問題が修正されることを願っています。これは大きな問題ではありません。誤って、1つのコンセントと特にそのフェイスビューに複数のキーまたは異なる名前キーがあります。

関連する問題