title: CoreData Swift: Fatal error: unexpectedly found nil while unwrapping an Optional value
body: <pre><code>override func viewWillDisappear(animated: Bool) {
      // need to add a device?
      if profile == nil {
          if let name = nameTextField.text, species = speciesTextField.text, dob: NSDate = datePicker.date, entity = NSEntityDescription.entityForName("Profile", inManagedObjectContext: managedObjectContext) where !name.isEmpty &amp;&amp; !species.isEmpty {
              profile = Profile(entity: entity, insertIntoManagedObjectContext: managedObjectContext)
              profile?.name = name
              profile?.species = species
              profile?.dob = dob
          }
      }
  }
  </code></pre>
  
  <p>Whenever I run my app, this part of code produces 'Fatal error: unexpectedly found nil while unwrapping an Optional value'. I am certain that name,species and dob do contain data as it shows in the console. Do you have any idea what variable could contain nil? I am using core data and am unfamiliar with it.</p>
  
  <p><strong>Screen:</strong>
  <img src="https://i.stack.imgur.com/fzBMt.png" alt="enter image description here"></p>
  
  <p><strong>Entities:</strong>
  <img src="https://i.stack.imgur.com/hxwBd.png" alt="enter image description here"></p>