title: Core Data NSManagedObject downcast with XCode 7 and Swift
body: <p>Running the following code aborts in the return line </p>
  
  <pre><code>Type is not Workout 
  Could not cast value of type 
  'NSManagedObject_Workout_' (0x7fcca20620f0) to 
  'AppName.Workout' (0x100ea5f40)). 
  </code></pre>
  
  <p>The part inside if let... is never executed.</p>
  
  <pre><code>func createWorkoutWithName (name: String) -&gt; Workout? {
      let entityName = NSStringFromClass(Workout.classForCoder())
      let newEntity = NSEntityDescription.insertNewObjectForEntityForName(entityName, inManagedObjectContext: managedObjectContext)
      if let newEntity = newEntity as? Workout {
          newEntity.name = name
      }
      NSLog("createWorkoutWithName: Type is not Workout")
      return (newEntity as! Workout)
  
  }
  </code></pre>
  
  <p>I had this problem in the past and I solved it in XCode 6.x by going in the entity inspector and setting Class = AppName.Workout</p>
  
  <p>One of several answers that suggests this solution is
  <a href="https://stackoverflow.com/questions/24154117/how-come-i-can-cast-to-nsmanagedobject-but-not-to-my-entitys-type">How come I can cast to NSManagedObject but not to my entity&#39;s type?</a></p>
  
  <p>XCode 7 adds a new twist to this problem:
  When I set</p>
  
  <pre><code>Class = AppName.Workout
  </code></pre>
  
  <p>in the entity inspector, XCode 7 changes the class name automagically to</p>
  
  <pre><code>Class = AppNameWorkout
  </code></pre>
  
  <p>by removing the dot between AppName and ClassName.</p>
  
  <p>So how can I do this in XCode 7 when I can't set a dot between AppName and ClassName?</p>