User defaults stored value is not persistent after terminating app

I am new to programming and trying to make a quiz app in swift. I want to save level1 score in user defaults and if it is greater than some number, the user can proceed to level 2. The problem is that every time I terminate the app and open it again, I get the message on console Terminated due to signal 9. I can't get the UserDefaults Integer printed out. How can I fix this?

class secViewController: UIViewController {
    var level1score:Int = 0
    let default1 = UserDefaults.standard

    override func viewDidLoad() {
        super.viewDidLoad()

        default1.set(level1score, forKey: "level1")
        print (default1.value(forKey: "level1"))
}