I have a Core Data / Swift Cocoa application project in Xcode 6 (let\'s call the project Stuff
). I created a Core Data entity called Query
and used Xco
I have a project with CoreData in pure Swift, no bridging header files and tests are working. Here's how I've managed to do:
My project name is cars and I have a NSManagedObject called Car
Car.swift:
Car.swift file Target Membership:
cars.xcdatamodeld Data Model Inspector:
You can use NSManagedObject
directly in Swift as follows:
class Query : NSManagedObject {
@NSManaged var attrOne : attrOneType
// ...
}
Currently Xcode won't generate Swift code for an entity; it still only generates Objective-C which may lead you to a bridging solution. But, you don't need to bridge - just start with the generated Objective-C and write Swift code, with the @NSManaged
annotation.
Took me a while to figure this out. The ideal solution is to import the bridging header in the test target itself. Go in Build Settings
> Swift compiler
> Code Generation
and give the name of your bridging header.
Be careful, the test target is not selected by default. You have to select it in the scrollbar (it's located on the same line as General, info, build Settings, build Phases, and Build Rules).
This way, you will have the same bridging header for both your project and your different test targets.