title: This class is not a key value coding-compliant for the key
body: <p>I know this question has been asked many times, but all of the situations seem to be different then mine and I do not have the ability to comment. </p>
  
  <p>I am trying to learn how to make a UserDefault variable, but it keeps crashing. The error I am getting in the logs is:</p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSUnknownKeyException',
      reason: '[&lt;NSUserDefaults 0x1097d6bf8&gt; valueForUndefinedKey:]: this class is 
      not key value coding-compliant for the key AmountOfCoins.'
  </code></pre>
  
  <p>Here is all the times the UserDefault was used in my code:</p>
  
  <pre><code>    class GameScene: SKScene, SKPhysicsContactDelegate {
      var CoinCount = Int()
  </code></pre>
  
  <p>^Here I defined a variable to make accessing the coin count easier. </p>
  
  <pre><code>    override func didMove(to view: SKView) {
      if let x = UserDefaults.value(forKey: "AmountOfCoins") as? Int{
          CoinCount = x
      }
  </code></pre>
  
  <p>^ This was used to check if the AmountOfCoins was empty. I think I may have made a mistake here.</p>
  
  <pre><code>   func startGame() {
      score = 0
      CoinCount = UserDefaults.value(forKey: "AmountOfCoins") as! Int
      scoreview.text = "\(score)"
      coinview.text = "\(UserDefaults.value(forKey: "AmountOfCoins"))"
  }
  </code></pre>
  
  <p>^ Here is a function that is called when the game is started</p>
  
  <pre><code>        func addCoin(){
      run(SKAction.playSoundFileNamed("Coin.wav", waitForCompletion: false))
      CoinCount += 1
      UserDefaults.standard.set(CoinCount, forKey: "AmountOfCoins")
      scoreview.text = "\(UserDefaults.value(forKey: "AmountOfCoins"))"
      coinview.text = "\(CoinCount)"
  </code></pre>
  
  <p>^ And lastly here is a function that is called whenever a coin needs to be added.</p>
  
  <p>I have read a few different methods for fixing this error but I really don't understand how exactly it works. </p>