Core Data in XCFramework

I am trying to create a XCFramework with the functionality of core data.

I simplly create a xcdatamodel and one entity in it.

Something like this:

@objc(Conversation)
public class Conversation: NSManagedObject {

}

extension Conversation {

    @nonobjc public class func fetchRequest() -> NSFetchRequest {
        return NSFetchRequest(entityName: "Conversation")
    }

    @NSManaged public var message: String?
    @NSManaged public var date: Date?

}

} 

When I create the XCFramework, it won't compile in the host app.

(I create the XCFramework by using the xcodebuild -create-xcframework)

The error is :

@NSManaged not allowed on computed properties


In the swiftInterface I got something like this:


@objc(Conversation) public class Conversation : CoreData.NSManagedObject {
  @objc override dynamic public init(entity: CoreData.NSEntityDescription, insertInto context: CoreData.NSManagedObjectContext?)
  @objc deinit
}
extension Conversation {
  @nonobjc public class func fetchRequest() -> CoreData.NSFetchRequest<xcframeworktest.Conversation>
  @objc @NSManaged dynamic public var date: Foundation.Date? {
    @objc get
    @objc set
  }
  @objc @NSManaged dynamic public var message: Swift.String? {
    @objc get
    @objc set
  }
}


My question is: How to not generate the getter and setter for NSManaged attributes when creating the XCFramework?

Replies

I've also expierenced this, any help would be usefule.

I'm also seeing this when enabling "Build Libraries for Distribution" in our project. The @NSManaged properties are leading to swiftinterface output which is unusable due to the "@NSManaged not allowed on computed properties" error. These are from simple @NSManaged properties without custom getters/setters in our codebase.

Same here. I'd really love to use CoreData inside a xcframework. Any possibilities or progess?

Are you using an old compiler? This issue was fixed in October: https://github.com/apple/swift/pull/27676

Are you able to reproduce this on the Xcode beta or from a recent downloadable toolchain from Swift.org?

Looks like it is fixed in Xcode 11.4 beta. Thanks a lot!