title: Core Data fatal error: unexpectedly found nil while unwrapping an Optional value
body: <p>Currently getting fatal error: unexpectedly found nil while unwrapping an Optional value when executing this line of code <code>deliveries = employee.delievery?.allObjects as! [NSManagedObject]</code>  </p>
  
  <p>I'm currently sending an employee from another <code>tableView</code> like this <code>var employees : [NSManagedObject]!</code> and <code>prepareForSegue</code> like this</p>
  
  <pre><code>override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
      if segue == "DelieverySegue"{
          let employeeDeliveries = segue.destinationViewController as! DelieveryTableViewController
  
  
  
          let indexPath = self.tableView.indexPathForSelectedRow
  
  
  
          let selectedEmployee = employees[indexPath!.row] as! Employee
  
          employeeDeliveries.employee = selectedEmployee
  
  
  
  
  
      }
  }
  </code></pre>
  
  <p>The reason why i <code>prepareForSegue</code> like this is because the <code>tableView</code> I'm segueing to has  a variable <code>var employee: Employee!</code></p>
  
  <p>Once i go to segue it crashes at this line of code in my <code>DeliveryTableViewController</code> in the <code>viewDidLoad()</code></p>
  
  <p><code>deliveries = employee.delievery?.allObjects as! [NSManagedObject]</code></p>
  
  <p>What my <code>NSManagedObject</code> looks like for both.</p>
  
  <p><code>extension Employee {</code></p>
  
  <pre><code>@NSManaged var first: String?
  @NSManaged var last: String?
  @NSManaged var phoneNumber: String?
  @NSManaged var wage: NSNumber?
  @NSManaged var id: NSNumber?
  @NSManaged var delievery: NSSet?
  </code></pre>
  
  <p><code>}</code></p>
  
  <p><code>extension Delivery {</code></p>
  
  <pre><code>@NSManaged var address: String?
  @NSManaged var phoneNumber: String?
  @NSManaged var subTotal: NSNumber?
  @NSManaged var total: NSNumber?
  @NSManaged var employee: Employee?
  </code></pre>
  
  <p><code>}</code></p>
  
  <p>and this is how I'm setting the relationship in my other <code>viewController</code> that creates a new delivery</p>
  
  <p><code>@IBAction func saveButton(sender: AnyObject) {</code></p>
  
  <pre><code>    let description = NSEntityDescription.entityForName("Employee", inManagedObjectContext: manageObjectContext)
  
  
      let employee = Employee(entity: (description)!, insertIntoManagedObjectContext: manageObjectContext)
      employee.first = first.text
      employee.last = last.text
      employee.phoneNumber = phoneNumber.text
      employee.wage = Float(wage.text!)
      employee.id = Int(employeeId.text!)
  
  
      do{
          try
          manageObjectContext.save()
          first.text = ""
          last.text = ""
          phoneNumber.text = ""
          wage.text = ""
          employeeId.text = ""
          status.text = "Success!"
  
  
  
      }catch let error as NSError{
  
          status.text = error.localizedFailureReason
      }
  </code></pre>
  
  <p><code>}</code></p>
  
  <p>am i casting it wrong?.. i have established a relationship between Employee and Delivery already. I'm currently trying to display the deliveries of the employee i am sending when clicking on a specific employee in the <code>EmployeeTableViewController</code> any help regarding this would be extremely helpful thank you for your time.</p>
  
  <p>What i get at run time, it fails after segueing to <code>DeliveryTableViewController</code></p>
  
  <p><a href="https://i.stack.imgur.com/wHlI2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wHlI2.png" alt="What i get after segueing to DeliveryTableViewController"></a></p>