When I try to flush the selected NSManagedObject into the appropriate subclass StoryPhotoTrackin my (Swift) unit tests, I get a runtime error:Could not cast value of type 'StoryPhotoTrack_StoryPhotoTrack_' (0x7fbda4734490) to 'StoryPhotoTrack' (0x11edd1b08).
Here is my failure / failure:
func testFetchingStoryWithCastingInvolved() {
let story : StoryPhotoTrack? = storyFetcher.fetchAnyStoryPhotoTrack()
XCTAssertNotNil(story, "should be a story")
let definitlyAStory : StoryPhotoTrack = story!
let object : NSManagedObject = story as NSManagedObject!
println(NSStringFromClass(definitlyAStory.dynamicType))
let downCastedStory : StoryPhotoTrack = object as! StoryPhotoTrack
XCTAssertNotNil(downCastedStory, "should still be a story")
}
func fetchAnyStoryPhotoTrackVia_ObjectiveC_Fetcher() -> StoryPhotoTrack? {
let object = StoryPhotoTrack.fetchAnyStoryPhotoTrackInContext(moc)
return object as StoryPhotoTrack?
}
Actual fetching is done in Objective-C:
+ (StoryPhotoTrack *)fetchAnyStoryPhotoTrackInContext:(NSManagedObjectContext *)moc
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"StoryPhotoTrack"];
NSArray *storyTracks = [moc executeFetchRequest:request error:nil];
return (StoryPhotoTrack *)[storyTracks lastObject];
}
I guess this has something to do with Swift space spaces. It seems my StoryPhotoTrack class is actually called StoryPhotoTrack_StoryPhotoTrack_.
I tried to rename the class names of my main data entities using the projectName prefixes (as suggested here ), but that didn't help. I tried both my main target module name and my test target module name, none of them worked.


What am I doing wrong?
edit: , , Swift, , , , . ?