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 theXCDataModel
.Declaration
Swift
static var entityName: String
-
init(managedObjectContext:)
Extension methodCreates a new instance of the Entity within the specified
NSManagedObjectContext
.Declaration
Swift
public init(managedObjectContext: NSManagedObjectContext)
-
entityDescription(in:)
Extension methodCreates an
NSEntityDescription
of theCoreDataModelable
entity using theentityName
Declaration
Swift
static public func entityDescription(in context: NSManagedObjectContext) -> NSEntityDescription!
-
fetchRequestForEntity(inContext:)
Extension methodCreates a new fetch request for the
CoreDataModelable
entity.Declaration
Swift
static public func fetchRequestForEntity(inContext context: NSManagedObjectContext) -> NSFetchRequest<Self>
-
findFirstInContext(_:predicate:)
Extension methodFetches 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?
-
allInContext(_:predicate:sortDescriptors:)
Extension methodFetches 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 methodReturns 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 methodRemoves all entities from within the specified
NSManagedObjectContext
.Throws
Any error produced from
executeFetchRequest
Declaration
Swift
static public func removeAllInContext(_ context: NSManagedObjectContext) throws
-
removeAllInContext(_:except:)
Extension methodRemoves 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