title: Assigning text field value to variable in Swift
body: <p>I am trying to learn Swift and it is turning out to be more different from other languages than I expected...</p>
  
  <p>I just want to store the value of a user's input as an integer in a variable.</p>
  
  <p>My attempts result in the following error:
  "fatal error: unexpectedly found nil while unwrapping an Optional value"</p>
  
  <p>I have tried this multiple ways and can't seem to come up with a solution, I know there must a simple way to do this.</p>
  
  <pre><code>var intNumber: Int = 0
  @IBOutlet weak var txt_Number: UITextField!
  
  for view in self.view.subviews as [UIView]{
  if let txt = view as? UITextField
  {
      if let txtData = txt.text where txtData.isEmpty
      {
          // Error Message
      }
      else
      {
          intNumber = Int(txt_Number.text)
      }
  }
  }
  </code></pre>
  
  <p>I know the above code isn't correct, but I think that's the closest to correct I have come. I seem to be missing something as far as unwrapping goes. I understand the principal of unwrapping, but nothing I have tried will compile, or if it does compile then it fails with the error above when the code is initiated (code is initiated when a button is pressed).</p>
  
  <p>Thank you in advanced for any help!</p>