Nice programing

포착되지 않은 예외 :이 클래스는 키 값 코딩을 준수하지 않습니다.

nicepro 2020. 12. 31. 23:27
반응형

포착되지 않은 예외 :이 클래스는 키 값 코딩을 준수하지 않습니다.


"iOS 용 Swift Tutorial : NSFileManager Persisting Data"라는 제목의 자습서를 따르고 있는데 29 분 표시 전후에 오류가 발생했습니다. iOS 시뮬레이터에서 실행하려고하면 오류가 발생합니다.

포착되지 않은 예외 'NSUnknownKeyException'으로 인해 앱 종료, 이유 : '[setValue : forUndefinedKey :] :이 클래스는 theLoadMethod 키에 대해 키 값 코딩을 준수하지 않습니다.'

분명히 오류를 기반으로 문제가 내 theLoadMethod. ViewController에서이 프로젝트의 일부로 작성한 모든 코드 는 다음과 같습니다 .

let theDocumentsFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let theFileName     = "/theUserFile.txt"
let thePath         = theDocumentsFolder.stringByAppendingString(theFileName)


class ViewController: UIViewController {

@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var ageTextField: UITextField!

@IBOutlet weak var theLabel: UILabel!

// The save method
@IBAction func theSaveMethod(sender: AnyObject) {
    var name        = nameTextField.text
    var lastName    = lastNameTextField.text
    var age         = ageTextField.text

    var theString   =   "The user's information is: \(name), \(lastName), \(age)"

    let theFileManager = NSFileManager.defaultManager()

    if !theFileManager.fileExistsAtPath(thePath) {

        var writeError:NSError?
        let fileToBeWritten = theString.writeToFile(thePath, atomically: true, encoding: NSUTF8StringEncoding, error: &writeError)

        if writeError == nil {
            println("No errors. Added: \(theString)")
        } else {
            println("Encountered an error. Error is: \(writeError)")
        }

    } else {
        println("File already exists")
    }

    nameTextField.resignFirstResponder()
    lastNameTextField.resignFirstResponder()
    ageTextField.resignFirstResponder()
}

@IBAction func theLoadMethod(sender: AnyObject) {
    let infoFromFile:String = String.stringWithContentsOfFile(thePath, encoding: NSUTF8StringEncoding, error: nil)!

    theLabel.text = infoFromFile
}

내가 뭘 잘못하고 있니? 내가 아는 한 모든 iOS 화면 요소는 올바르게 이름이 지정되고 연결됩니다.


이는 일반적으로 스토리 보드에서 존재하지 않는 속성으로의 링크로 인해 발생합니다. 스토리 보드에있는 개체의 모든 링크를 다시 확인하십시오. 또한 속성 또는 메서드의 이름이나 철자를 변경 한 경우에도 이전 항목에 대한 참조를 가질 수 있습니다.


같은 문제에 직면하고 있고 IBOutlet이 괜찮은지 이미 확인한 사람들을 위해 (최소한 Interface Builder에서 괜찮아 보임) ​​: 뷰 컨트롤러에 대한 모듈 (첨부 된 이미지 참조)이 "Current-$ (PROJECT_NAME) ". enter image description here


I was having a similar issue. I had changed the fields required by the user and renamed a couple of fields.

I made all the necessary changes in parse (dropped and added columns). The backend was not the problem.

Your interface builder source code still contains the old attributes.

To solve right click on main.storyboard -> Open As -> Source Code....look for the fields that you removed or renamed ...delete or modified them ...it depends changes you made.

in your case did you rename theLoadMethod from something else?

hope this helps someone out there.

Cheers!


Simply navigate to your Main.storyboard code by right clicking and selecting the source code tab, then remove the previous entry which is stored (the application stores previous entries, just remove that).


I also encountered with a similar error. I solved the problem by means of changing Build Location to Custom in the settings of XCode after updating it. Just set this field to 'Relative to Workspace' and that's it.

ReferenceURL : https://stackoverflow.com/questions/26353378/uncaught-exception-this-class-is-not-key-value-coding-compliant

반응형