title: How come I can cast to NSManagedObject but not to my entity's type?
body: <p>I'm using the Swift boilerplate code for Core Data in a fresh project. My <code>.xcdatamodeld</code> file has a single entity defined (<code>Task</code>) with a single attribute (<code>name</code>).</p>
  
  <p>I have a <code>Task.swift</code> file that looks like this:</p>
  
  <pre><code>import CoreData
  
  class Task: NSManagedObject {
      @NSManaged var name: String
  }
  </code></pre>
  
  <p>When I run this, it works:</p>
  
  <pre><code>var firstTask = NSEntityDescription.insertNewObjectForEntityForName("Task",
      inManagedObjectContext: managedObjectContext) as NSManagedObject
  
  firstTask.setPrimitiveValue("File my TPS reports", forKey: "name")
  
  var error: NSError?
  
  managedObjectContext.save(&amp;error)
  </code></pre>
  
  <p>I can even go into the SQLite database being used by the iOS simulator and confirm that the row was added.</p>
  
  <p>However, when I run the exact same code as above but with <code>as Task</code> instead of <code>as NSManagedObject</code>, I get a crash with the error message <code>Thread 1: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)</code>, associated with the <code>var firstTask</code>… line. If I continue execution, I get <code>EXC_BAD_ACCESS</code> and <code>0 misaligned_stack_error_</code> at the top of Thread 1 each time I advance it.</p>
  
  <p>Why might this cast lead to all this?</p>