title: Learning Swift, Value of optional type not unwrapped when creating an object
body: <p>I'm learning Swift right now, and in the course we have a lesson to make a simple app. Now I'm having problems with some text fields programming that it's not working properly.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>class ViewController: UIViewController {
  
      @IBOutlet weak var refeicaoField: UITextField?
      @IBOutlet weak var felicidadeField: UITextField?
  
  
      @IBAction func addRefeicao(sender: UIButton) {
  
          if refeicaoField == nil || felicidadeField == nil {
              return
          }
  
          let nomeRefeicao = refeicaoField!.text
          let valorFelicidade = felicidadeField!.text
          let valorFelicidadeInt = Int(valorFelicidade!)
  
          let novaRefeicao = Meal(nomeAlimento: nomeRefeicao, alegriaEmComer: valorFelicidadeInt)
      }
  
  
  }
  </code></pre>
  
  <p>The problem starts here:</p>
  
  <pre><code>    let novaRefeicao = Meal(nomeAlimento: nomeRefeicao, alegriaEmComer: valorFelicidadeInt)
  </code></pre>
  
  <p>Where it says: value of optional 'Int?' not unwrapped; did you mean to use '!' or '?' and also value of optional 'String?' not unwrapped; did you mean to use '!' or '?'</p>
  
  <p>I'm little confused, because in the lesson example they have done like this:</p>
  
  <pre><code>    let novaRefeicao = Meal(nomeAlimento: nomeRefeicao, alegriaEmComer: valorFelicidadeInt!)
  </code></pre>
  
  <p>And worked, but for me no. And if I try to put '!' at the two variables, I have an exclamation warning prompting no use for let novaRefeicao.</p>
  
  <p>What's wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Done some changes using all the tips found here, now my code is like:</p>
  
  <pre><code>class ViewController: UIViewController {
  
      @IBOutlet weak var refeicaoField: UITextField!
      @IBOutlet weak var felicidadeField: UITextField!
  
  
      @IBAction func addRefeicao(sender: UIButton) {
  
          if refeicaoField == nil || felicidadeField == nil {
              return
          }
  
          let nomeRefeicao = refeicaoField!.text
          let valorFelicidade = felicidadeField!.text
  
          if nomeRefeicao == nil {
              return
          }
  
          if let valorFelicidadeInt = Int(valorFelicidade!) {
              let novaRefeicao = Meal(nomeAlimento: nomeRefeicao, alegriaEmComer: valorFelicidadeInt)
          } else {
              return
          }
      }
  
  
  }
  </code></pre>
  
  <p>Now I receive the error on unwrapped again, but now with the "nomeRefeicao" instead. Tried to put the '!' in it, but then it shows that let novaRefeicao is immutable value.</p>