NSFetchRequestResult
-
Mechanica
The entity name.
Declaration
Swift
public static var entityName: String
-
Mechanica
Creates a
new
NSFetchRequest forself
.Declaration
Swift
public static func fetchRequest() -> NSFetchRequest<Self>
-
Mechanica
Attempts to find an object matching a predicate or creates a new one and configures it.
Declaration
Swift
public static func findOrCreate(in context: NSManagedObjectContext, where predicate: NSPredicate, with configuration: (Self) -> Void) -> Self
Parameters
context
Searched context.
predicate
Matching predicate.
configuration
Configuration closure called only when creating a new object.
Return Value
A matching object or a configured new one.
-
Mechanica
Tries to find an existing object in the context (memory) matching a predicate; if it doesn’t find the object in the context, tries to load it using a fetch request (if multiple objects are found, returns the first one).
Declaration
Swift
public static func findOrFetch(in context: NSManagedObjectContext, where predicate: NSPredicate) -> Self?
Parameters
context
Searched context.
predicate
Matching predicate.
Return Value
A matching object (if any).
-
Mechanica
Performs a configurable fetch request in a context.
Declaration
Swift
public static func fetch(in context: NSManagedObjectContext, with configuration: (NSFetchRequest<Self>) -> Void = { _ in }) -> [Self]
-
Mechanica
Counts the results of a configurable fetch request in a context.
Declaration
Swift
public static func count(in context: NSManagedObjectContext, for configuration: (NSFetchRequest<Self>) -> Void = { _ in }) -> Int
-
Mechanica
Iterates over the context’s registeredObjects set (which contains all managed objects the context currently knows about) until it finds one that is not a fault matching a given predicate. Faulted objects are not considered to to prevent Core Data to make a round trip to the persistent store.
Declaration
Swift
public static func findMaterializedObject(in context: NSManagedObjectContext, where predicate: NSPredicate) -> Self?
-
Mechanica
Executes a fetch request where only a single object is expected as result, otherwhile a fatal error occurs.
Declaration
Swift
public static func fetchSingleObject(in context: NSManagedObjectContext, with configuration: @escaping (NSFetchRequest<Self>) -> Void) -> Self?
-
Mechanica
Tries to retrieve an object from the cache; if there’s nothing in the cache executes the fetch request and caches the result (if a single object is found).
Declaration
Swift
public static func fetchCachedObject(in context: NSManagedObjectContext, forKey cacheKey: String, with configuration: @escaping (NSFetchRequest<Self>) -> Void) -> Self?
Parameters
context
Searched context.
cacheKey
Cache key.
configuration
Configurable fetch request.
Return Value
A cached object (if any).
-
Mechanica
Makes a batch delete for object conforming to
DelayedDeletable
older than thecutOffDate
date.Throws
An error in cases of a batch delete operation failure.Declaration
Swift
public static func batchDeleteObjectsMarkedForDeletion(in context: NSManagedObjectContext, olderThan cutOffDate: Date = Date(timeIntervalSinceNow: -TimeInterval(120))) throws
Parameters
context
The NSManagedObjectContext where is executed the batch delete request.
cutOffDate
Objects marked for local deletion more than this time (in seconds) ago will get permanently deleted.