SHARE
TWEET

Untitled

a guest Jun 20th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @objc(Entity)
  2. public class Entity: NSManagedObject {
  3.  
  4.     class var entityName: String {
  5.         return String(describing: self)
  6.     }
  7.  
  8.     private var testClass = MyTestClass()
  9.  
  10.     init() {
  11.         let entityName: String = type(of: self).entityName
  12.         let context: NSManagedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
  13.         guard let entityDescription: NSEntityDescription = NSEntityDescription.entity(forEntityName: entityName, in: context) else {
  14.             fatalError("Failed to create entity description for name: (entityName)")
  15.         }
  16.         super.init(entity: entityDescription, insertInto: context)
  17.  
  18.         print(testClass.testProperty)
  19.     }
  20. }
  21.  
  22. extension Entity {
  23.  
  24.     @nonobjc public class func fetchRequest() -> NSFetchRequest<Entity> {
  25.         return NSFetchRequest<Entity>(entityName: "Entity")
  26.     }
  27.  
  28.     @NSManaged public var title: String?
  29.  
  30. }
  31.      
  32. @objc(EntityChild)
  33. public class EntityChild: Entity {
  34.  
  35.     private var testClassChild = MyTestClass()
  36.  
  37.     override init() {
  38.         super.init()
  39.  
  40.         print(testClassChild.testProperty)
  41.     }
  42. }
  43.  
  44. extension EntityChild {
  45.  
  46.     @nonobjc public class func fetchRequest() -> NSFetchRequest<EntityChild> {
  47.         return NSFetchRequest<EntityChild>(entityName: "EntityChild")
  48.     }
  49.  
  50.     @NSManaged public var title2: String?
  51.  
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top