2

I am wondering if there is any way to prevent core data from generating public classes from core data model Entities.

Currently it generates classes like this:

import Foundation
import CoreData


public class MyEntityMO: NSManagedObject {

}

extension MyEntityMO {

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

    @NSManaged public var someBoolean: Bool
}

But I want to it be like this (to use internal access modifiers):

import Foundation
import CoreData


internal class MyEntityMO: NSManagedObject {

}

extension MyEntityMO {

    @nonobjc internal class func fetchRequest() -> NSFetchRequest<RecordSettingMO> {
        return NSFetchRequest<RecordSettingMO>(entityName: "RecordSettingMO")
    }

    @NSManaged internal var someBoolean: Bool
}
StaceyGirl
  • 6,826
  • 12
  • 33
  • 59

1 Answers1

2

Xcode does not offer any way to make this change. To use internal, you would need to turn off automatic subclass generation and create your own subclasses instead.

You could use the code you have in your question. Get the current code, save a copy, and turn off automatic generation. Then edit your copy. But you'll have to make all future edits yourself too, so if you change the model in the future, make sure to edit your subclass as well.

Tom Harrington
  • 62,792
  • 9
  • 129
  • 149