Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @objc(Entity)
- public class Entity: NSManagedObject {
- class var entityName: String {
- return String(describing: self)
- }
- private var testClass = MyTestClass()
- init() {
- let entityName: String = type(of: self).entityName
- let context: NSManagedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
- guard let entityDescription: NSEntityDescription = NSEntityDescription.entity(forEntityName: entityName, in: context) else {
- fatalError("Failed to create entity description for name: (entityName)")
- }
- super.init(entity: entityDescription, insertInto: context)
- print(testClass.testProperty)
- }
- }
- extension Entity {
- @nonobjc public class func fetchRequest() -> NSFetchRequest<Entity> {
- return NSFetchRequest<Entity>(entityName: "Entity")
- }
- @NSManaged public var title: String?
- }
- @objc(EntityChild)
- public class EntityChild: Entity {
- private var testClassChild = MyTestClass()
- override init() {
- super.init()
- print(testClassChild.testProperty)
- }
- }
- extension EntityChild {
- @nonobjc public class func fetchRequest() -> NSFetchRequest<EntityChild> {
- return NSFetchRequest<EntityChild>(entityName: "EntityChild")
- }
- @NSManaged public var title2: String?
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement