FetchableSource
public protocol FetchableSource : AnyObject
Encapsulates containers which manages an internal NSManagedObjectContext
, such as DataStack
s and transactions, that can be used for fetching objects. CoreStore provides implementations for this protocol and should be used as a read-only abstraction.
-
Fetches the
DynamicObject
instance in theFetchableSource
‘s context from a reference created from another managed object context.Declaration
Swift
func fetchExisting<O>(_ object: O) -> O? where O : DynamicObject
Parameters
object
a reference to the object created/fetched outside the
FetchableSource
‘s contextReturn Value
the
DynamicObject
instance if the object exists in theFetchableSource
‘s context, ornil
if not found. -
Fetches the
DynamicObject
instance in theFetchableSource
‘s context from anNSManagedObjectID
.Declaration
Swift
func fetchExisting<O>(_ objectID: NSManagedObjectID) -> O? where O : DynamicObject
Parameters
objectID
the
NSManagedObjectID
for the objectReturn Value
the
DynamicObject
instance if the object exists in theFetchableSource
, ornil
if not found. -
Fetches the
DynamicObject
instances in theFetchableSource
‘s context from references created from another managed object context.Declaration
Swift
func fetchExisting<O, S>(_ objects: S) -> [O] where O : DynamicObject, O == S.Element, S : Sequence
Parameters
objects
an array of
DynamicObject
s created/fetched outside theFetchableSource
‘s contextReturn Value
the
DynamicObject
array for objects that exists in theFetchableSource
-
Fetches the
DynamicObject
instances in theFetchableSource
‘s context from a list ofNSManagedObjectID
.Declaration
Swift
func fetchExisting<O, S>(_ objectIDs: S) -> [O] where O : DynamicObject, S : Sequence, S.Element == NSManagedObjectID
Parameters
objectIDs
the
NSManagedObjectID
array for the objectsReturn Value
the
DynamicObject
array for objects that exists in theFetchableSource
‘s context -
Fetches the first
DynamicObject
instance that satisfies the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchOne<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> O? where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
the first
DynamicObject
instance that satisfies the specifiedFetchClause
s, ornil
if no match was found -
Fetches the first
DynamicObject
instance that satisfies the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchOne<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> O? where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
the first
DynamicObject
instance that satisfies the specifiedFetchClause
s, ornil
if no match was found -
Fetches the first
DynamicObject
instance that satisfies the specifiedFetchChainableBuilderType
built from a chain of clauses.let youngestTeen = source.fetchOne( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )
Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchOne<B>(_ clauseChain: B) throws -> B.ObjectType? where B : FetchChainableBuilderType
Parameters
clauseChain
a
FetchChainableBuilderType
built from a chain of clausesReturn Value
the first
DynamicObject
instance that satisfies the specifiedFetchChainableBuilderType
, ornil
if no match was found -
Fetches all
DynamicObject
instances that satisfy the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchAll<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [O] where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
all
DynamicObject
instances that satisfy the specifiedFetchClause
s, or an empty array if no match was found -
Fetches all
DynamicObject
instances that satisfy the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchAll<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [O] where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
all
DynamicObject
instances that satisfy the specifiedFetchClause
s, or an empty array if no match was found -
Fetches all
DynamicObject
instances that satisfy the specifiedFetchChainableBuilderType
built from a chain of clauses.let people = source.fetchAll( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )
Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchAll<B>(_ clauseChain: B) throws -> [B.ObjectType] where B : FetchChainableBuilderType
Parameters
clauseChain
a
FetchChainableBuilderType
built from a chain of clausesReturn Value
all
DynamicObject
instances that satisfy the specifiedFetchChainableBuilderType
, or an empty array if no match was found -
Fetches the number of
DynamicObject
s that satisfy the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchCount<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> Int where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
the number of
DynamicObject
s that satisfy the specifiedFetchClause
s -
Fetches the number of
DynamicObject
s that satisfy the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchCount<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> Int where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
the number of
DynamicObject
s that satisfy the specifiedFetchClause
s -
Fetches the number of
DynamicObject
s that satisfy the specifiedFetchChainableBuilderType
built from a chain of clauses.let numberOfAdults = source.fetchCount( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )
Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchCount<B>(_ clauseChain: B) throws -> Int where B : FetchChainableBuilderType
Parameters
clauseChain
a
FetchChainableBuilderType
built from a chain of clausesReturn Value
the number of
DynamicObject
s that satisfy the specifiedFetchChainableBuilderType
-
Fetches the
NSManagedObjectID
for the firstDynamicObject
that satisfies the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
the
NSManagedObjectID
for the firstDynamicObject
that satisfies the specifiedFetchClause
s, ornil
if no match was found -
Fetches the
NSManagedObjectID
for the firstDynamicObject
that satisfies the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
the
NSManagedObjectID
for the firstDynamicObject
that satisfies the specifiedFetchClause
s, ornil
if no match was found -
Fetches the
NSManagedObjectID
for the firstDynamicObject
that satisfies the specifiedFetchChainableBuilderType
built from a chain of clauses.let youngestTeenID = source.fetchObjectID( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )
Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchObjectID<B>(_ clauseChain: B) throws -> NSManagedObjectID? where B : FetchChainableBuilderType
Parameters
clauseChain
a
FetchChainableBuilderType
built from a chain of clausesReturn Value
the
NSManagedObjectID
for the firstDynamicObject
that satisfies the specifiedFetchChainableBuilderType
, ornil
if no match was found -
Fetches the
NSManagedObjectID
for allDynamicObject
s that satisfy the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
the
NSManagedObjectID
for allDynamicObject
s that satisfy the specifiedFetchClause
s, or an empty array if no match was found -
Fetches the
NSManagedObjectID
for allDynamicObject
s that satisfy the specifiedFetchClause
s. AcceptsWhere
,OrderBy
, andTweak
clauses.Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] where O : DynamicObject
Parameters
from
a
From
clause indicating the entity typefetchClauses
a series of
FetchClause
instances for the fetch request. AcceptsWhere
,OrderBy
, andTweak
clauses.Return Value
the
NSManagedObjectID
for allDynamicObject
s that satisfy the specifiedFetchClause
s, or an empty array if no match was found -
Fetches the
NSManagedObjectID
for allDynamicObject
s that satisfy the specifiedFetchChainableBuilderType
built from a chain of clauses.let idsOfAdults = source.fetchObjectIDs( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )
Throws
CoreStoreError.persistentStoreNotFound
if the specified entity could not be found in any store’s schema.Declaration
Swift
func fetchObjectIDs<B>(_ clauseChain: B) throws -> [NSManagedObjectID] where B : FetchChainableBuilderType
Parameters
clauseChain
a
FetchChainableBuilderType
built from a chain of clausesReturn Value
the
NSManagedObjectID
for allDynamicObject
s that satisfy the specifiedFetchChainableBuilderType
, or an empty array if no match was found -
The internal
NSManagedObjectContext
managed by thisFetchableSource
. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.Declaration
Swift
func unsafeContext() -> NSManagedObjectContext