title: Swift 3: If let statement crashes instead of executing else block
body: <p>I am trying to figure out how Swift 3 handles unwrapping with the <code>if let</code> syntax. My scenario is I want to make a fetch from CoreData in an <code>if let</code> statement. I want to unwrap the value there and if there is a value (not nil), then use it. If there is not a value, perform what is in the <code>else</code> block. Seems to make sense, but in my experience this is not what Swift 3 thinks.</p>
  
  <p><strong><em>NOTE</strong>: there are NO "Object" entities to be returned. I WANT it to drop down to print "No Objects".</em></p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>// How I'm making the fetch from CoreData
  class func getAllObjects() -&gt; [Object]? {
      let appDelegate = UIApplication.shared.delegate as! AppDelegate
      let context = appDelegate.managedObjectContext
      let fetchRequest = NSFetchRequest&lt;Object&gt;(entityName: "Object")
      let fetched = try! context.fetch(fetchRequest)
      return fetched
  }
  
  // Unwrapping value: How I'd do it... But Xcode didn't like...
  if let fetchedObjects = WorkOrder.getAllObjects() as? [Order] {
      self.objects = fetchedObjects
  }
  else {
      print("No Objects")
  }
  
  // Unwrapping value: How Xcode "corrected" my code and this compiles
  if let fetchedObjects = WorkOrder.getAllObjects()! as [Order]? {
      self.objects = fetchedObjects
  }
  else {
      print("No Objects")
  }
  </code></pre>
  
  <p><strong>WHAT HAPPENS</strong></p>
  
  <p>The app crashes. It found nil while unwrapping an option value. I thought the <code>if let</code> was supposed to guard against my app crashing. Because if there isn't anything valid to unwrap it should execute the <code>else</code> block. Right?</p>
  
  <p><strong>QUESTION</strong></p>
  
  <p>Do you know of a way to have <code>if let</code> to behave in the way I suggested above? Or code that <em>will</em> behave as such?</p>