CoreDataModelable

@objc public protocol CoreDataModelable: NSFetchRequestResult

Protocol to be conformed to by NSManagedObject subclasses that allow for convenience methods that make fetching, inserting, deleting, and change management easier.

  • The name of your NSManagedObject‘s entity within the XCDataModel.

    Declaration

    Swift

    static var entityName: String
  • init(managedObjectContext:) Extension method

    Creates a new instance of the Entity within the specified NSManagedObjectContext.

    Declaration

    Swift

    public init(managedObjectContext: NSManagedObjectContext)
  • entityDescription(in:) Extension method

    Creates an NSEntityDescription of the CoreDataModelable entity using the entityName

    Declaration

    Swift

    static public func entityDescription(in context: NSManagedObjectContext) -> NSEntityDescription!
  • Creates a new fetch request for the CoreDataModelable entity.

    Declaration

    Swift

    static public func fetchRequestForEntity(inContext context: NSManagedObjectContext) -> NSFetchRequest<Self>
  • Fetches the first Entity that matches the optional predicate within the specified NSManagedObjectContext.

    Throws

    Any error produced from executeFetchRequest

    Declaration

    Swift

    static public func findFirstInContext(_ context: NSManagedObjectContext, predicate: NSPredicate? = nil) throws -> Self?
  • Fetches all Entities within the specified NSManagedObjectContext.

    Throws

    Any error produced from executeFetchRequest

    Declaration

    Swift

    static public func allInContext(_ context: NSManagedObjectContext, predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil) throws -> [Self]
  • countInContext(_:predicate:) Extension method

    Returns count of Entities that matches the optional predicate within the specified NSManagedObjectContext.

    Throws

    Any error produced from countForFetchRequest

    Declaration

    Swift

    static public func countInContext(_ context: NSManagedObjectContext, predicate: NSPredicate? = nil) throws -> Int
  • removeAllInContext(_:) Extension method

    Removes all entities from within the specified NSManagedObjectContext.

    Throws

    Any error produced from executeFetchRequest

    Declaration

    Swift

    static public func removeAllInContext(_ context: NSManagedObjectContext) throws
  • Removes all entities from within the specified NSManagedObjectContext excluding a supplied array of entities.

    Throws

    Any error produced from executeFetchRequest

    Declaration

    Swift

    static public func removeAllInContext(_ context: NSManagedObjectContext, except toKeep: [Self]) throws