How to access Core Data generated Obj-C classes in test targets?

后端 未结 3 518
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 06:14

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

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 06:52

    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.

提交回复
热议问题