Xcode错误:无法设置()用户定义的检查属性:此类不符合密钥的键值编码要求

时间:2019-05-04 13:58:31

标签: ios swift iphone xcode debugging

编辑

//  EnterValueScreen.swift
//  myfirstapp

import UIKit

class EnterValueScreen: UIViewController {

    override func viewDidLoad() {
        // Do any additional setup after loading the view.
    }

        // outlet fields


    @IBOutlet weak var enterValue: UITextField!
    var val: Double!
    var convertedVal: Double!
    var weightBool: Bool = true
    var weightName: String!

    @IBOutlet weak var outputLabel: UILabel!
    @IBOutlet weak var segmentControl: UISegmentedControl!
    //outputField.text = ans

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        enterValue.resignFirstResponder()
    }

    @IBAction func enterValueTouch(_ sender: UITextField) {
    }


    @IBAction func indexedWeight(_ sender: Any) {
        switch segmentControl.selectedSegmentIndex {
        case 0:
            weightBool = true
        case 1:
            weightBool = false
        default:
            weightBool = true
        }
    }
    //
    func convertEquations(_ weight: Bool, insertValueFromTextField value: Double) -> Double {

        if weight == true {
            print("we doin Kgs")
            convertedVal = 2.20462 * value
            weightName = "Pounds"


        } else {
            print("we doin lbs")
            convertedVal = value / 2.20462
            weightName = "Kilos"
        }

        return convertedVal.rounded(toPlaced: 1)
    }

    @IBAction func convertButton(_ sender: UIButton) {
        //execute function converter

        val = Double(enterValue.text ?? "0")

        convertEquations(weightBool, insertValueFromTextField: val)

        outputLabel.text = String(convertedVal) + " \(weightName!)"
    }
}


extension Double {
    func rounded(toPlaced places:Int) -> Double {
        let divisor = pow(10.0, Double(places))
        return (self * divisor).rounded() / divisor
    }
}

这是我得到的错误:

2019-05-06 11:45:01.601637 + 0100 myfirstapp [3695:385041]无法在(myfirstapp.EnterValueScreen)上设置()用户定义的检查属性:[setValue:forUndefinedKey:]:此类不是键值符合编码要求。 2019-05-06 11:45:04.016105 + 0100 myfirstapp [3695:385041] [MC] systemgroup.com.apple.configurationprofiles路径的系统组容器为/ Users / james / Library / Developer / CoreSimulator / Devices / 976DE92D-F68B -4608-9EC5-E68B0EB658A6 / data / Containers / Shared / SystemGroup / systemgroup.com.apple.configurationprofiles 2019-05-06 11:45:04.016549 + 0100 myfirstapp [3695:385041] [MC]从私人有效用户设置中读取。 2019-05-06 11:45:04.071007 + 0100 myfirstapp [3695:385041]找不到支持键盘iPhone-PortraitTruffle-NumberPad的类型4的键盘;使用20615_PortraitTruffle_iPhone-Simple-Pad_Default

1 个答案:

答案 0 :(得分:0)

尝试在您的super.viewDidLoad();方法中使用override func viewDidLoad()

喜欢

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
}

如果它不起作用,请尝试从情节提要中删除并重新连接viewController的连接。