title: Downcasting NSManagedObject in Swift Core Data
body: <p>I have a class that inherits from <code>NSManagedObject</code>. I'm using this object for model data and it's also being persisted.</p>
  
  <pre><code>class Foo: NSManagedObject {
  
     @NSManaged var firstVar: String
     @NSManaged var secondVar: String
  
    let entity = NSEntityDescription.entityForName("Foo",   inManagedObjectContext: managedObjectContext)
    let createdManagedObject = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedObjectContext) as? Foo
  
  }
  </code></pre>
  
  <p>I can create the object and get the <code>NSManagedObject</code> instance, but I can't downcast it to actual class.
  Actually, if I downcast it form optional value, then I will get nil value and if I downcast with unwrapping then it will crash. 
  When downcast with nil value debugger inspector shows type: <strong>Module.Foo</strong>, which I believe is the root of the problem.</p>
  
  <p>Of course I tried with naming the class in .xcmodel inspector, tried to name <strong>Entity</strong> as <strong>Module.Foo</strong>, but the latter is not allowed as of Xcode 7 any more anyway.</p>
  
  <p>All together: no success. Now I have to access <code>Foo</code> object through KV, which is kind of awkward.</p>
  
  <p>Anyone solved this issue yet?</p>
  
  <p><strong>EDIT</strong>: Adding the code to show creation and down-casting. I had issues with Xcode 7.0 and now same with 7.1.1</p>