BaseDataTransaction
public class BaseDataTransaction
extension BaseDataTransaction: FetchableSource, QueryableSource
The BaseDataTransaction is an abstract interface for NSManagedObject creates, updates, and deletes. All BaseDataTransaction subclasses manage a private NSManagedObjectContext which are direct children of the NSPersistentStoreCoordinator‘s root NSManagedObjectContext. This means that all updates are saved first to the persistent store, and then propagated up to the read-only NSManagedObjectContext.
-
Indicates if the transaction has pending changes
Declaration
Swift
public var hasChanges: Bool { get } -
Creates a new
NSManagedObjectorCoreStoreObjectwith the specified entity type.Declaration
Swift
public func create<O>(_ into: Into<O>) -> O where O : DynamicObjectParameters
intothe
Intoclause indicating the destinationNSManagedObjectorCoreStoreObjectentity type and the destination configurationReturn Value
a new
NSManagedObjectorCoreStoreObjectinstance of the specified entity type. -
Returns an editable proxy of a specified
NSManagedObjectorCoreStoreObject.Declaration
Swift
public func edit<O>(_ object: O?) -> O? where O : DynamicObjectParameters
objectthe
NSManagedObjectorCoreStoreObjecttype to be editedReturn Value
an editable proxy for the specified
NSManagedObjectorCoreStoreObject. -
Returns an editable proxy of the object with the specified
NSManagedObjectID.Declaration
Swift
public func edit<O>(_ into: Into<O>, _ objectID: NSManagedObjectID) -> O? where O : DynamicObjectParameters
intoan
Intoclause specifying the entity typeobjectIDthe
NSManagedObjectIDfor the object to be editedReturn Value
an editable proxy for the specified
NSManagedObjectorCoreStoreObject. -
Deletes the objects with the specified
NSManagedObjectIDs.Declaration
Swift
public func delete<S>(objectIDs: S) where S : Sequence, S.Element : NSManagedObjectIDParameters
objectIDsthe
NSManagedObjectIDs of the objects to delete -
Deletes the specified
NSManagedObjects orCoreStoreObjects represented by series ofObjectRepresentations.Declaration
Swift
public func delete<O>(_ object: O?, _ objects: O?...) where O : ObjectRepresentationParameters
objectthe
ObjectRepresentationrepresenting anNSManagedObjectorCoreStoreObjectto be deletedobjectsother
ObjectRepresentations representingNSManagedObjects orCoreStoreObjects to be deleted -
Deletes the specified
NSManagedObjects orCoreStoreObjects represented by anObjectRepresenation.Declaration
Swift
public func delete<S>(_ objects: S) where S : Sequence, S.Element : ObjectRepresentationParameters
objectsthe
ObjectRepresenations representingNSManagedObjects orCoreStoreObjects to be deleted -
Refreshes all registered objects
NSManagedObjects in the transaction.Declaration
Swift
public func refreshAndMergeAllObjects()
-
Returns
trueif the object has any property values changed. This method should not be called after thecommit()method was called.Declaration
Swift
public func objectHasPersistentChangedValues<O>(_ object: O) -> Bool where O : DynamicObjectParameters
objectthe
DynamicObjectinstanceReturn Value
trueif the object has any property values changed. -
Returns all pending
DynamicObjects of the specified type that were inserted to the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func insertedObjects<O>(_ entity: O.Type) -> Set<O> where O : DynamicObject, O : HashableParameters
entitythe
DynamicObjectsubclass to filterReturn Value
a
Setof pendingDynamicObjects of the specified type that were inserted to the transaction. -
Returns all pending
NSManagedObjectIDs that were inserted to the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func insertedObjectIDs() -> Set<NSManagedObjectID>Return Value
a
Setof pendingNSManagedObjectIDs that were inserted to the transaction. -
Returns all pending
NSManagedObjectIDs of the specified type that were inserted to the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func insertedObjectIDs<O>(_ entity: O.Type) -> Set<NSManagedObjectID> where O : DynamicObjectParameters
entitythe
DynamicObjectsubclass to filterReturn Value
a
Setof pendingNSManagedObjectIDs of the specified type that were inserted to the transaction. -
Returns all pending
DynamicObjects of the specified type that were updated in the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func updatedObjects<O>(_ entity: O.Type) -> Set<O> where O : DynamicObject, O : HashableParameters
entitythe
DynamicObjectsubclass to filterReturn Value
a
Setof pendingDynamicObjects of the specified type that were updated in the transaction. -
Returns all pending
NSManagedObjectIDs that were updated in the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func updatedObjectIDs() -> Set<NSManagedObjectID>Return Value
a
Setof pendingNSManagedObjectIDs that were updated in the transaction. -
Returns all pending
NSManagedObjectIDs of the specified type that were updated in the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func updatedObjectIDs<O>(_ entity: O.Type) -> Set<NSManagedObjectID> where O : DynamicObjectParameters
entitythe
DynamicObjectsubclass to filterReturn Value
a
Setof pendingNSManagedObjectIDs of the specified type that were updated in the transaction. -
Returns all pending
DynamicObjects of the specified type that were deleted from the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func deletedObjects<O>(_ entity: O.Type) -> Set<O> where O : DynamicObject, O : HashableParameters
entitythe
DynamicObjectsubclass to filterReturn Value
a
Setof pendingDynamicObjects of the specified type that were deleted from the transaction. -
Returns all pending
NSManagedObjectIDs of the specified type that were deleted from the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func deletedObjectIDs() -> Set<NSManagedObjectID>Parameters
entitythe
DynamicObjectsubclass to filterReturn Value
a
Setof pendingNSManagedObjectIDs of the specified type that were deleted from the transaction. -
Returns all pending
NSManagedObjectIDs of the specified type that were deleted from the transaction. This method should not be called after thecommit()method was called.Declaration
Swift
public func deletedObjectIDs<O>(_ entity: O.Type) -> Set<NSManagedObjectID> where O : DynamicObjectParameters
entitythe
DynamicObjectsubclass to filterReturn Value
a
Setof pendingNSManagedObjectIDs of the specified type that were deleted from the transaction.
-
An arbitrary value that identifies the source of this transaction. Callers of the transaction can provide this value through the
DataStack.perform(...)methods.Declaration
Swift
public let sourceIdentifier: Any? -
Allow external libraries to store custom data in the transaction. App code should rarely have a need for this.
enum Static { static var myDataKey: Void? } transaction.userInfo[&Static.myDataKey] = myObjectImportant
Do not use this method to store thread-sensitive data.Declaration
Swift
public let userInfo: UserInfo
-
Creates an
ImportableObjectby importing from the specified import source.Declaration
Swift
public func importObject<O: ImportableObject>( _ into: Into<O>, source: O.ImportSource) throws -> O?Parameters
intoan
Intoclause specifying the entity typesourcethe object to import values from
Return Value
the created
ImportableObjectinstance, ornilif the import was ignored -
Updates an existing
ImportableObjectby importing values from the specified import source.Declaration
Swift
public func importObject<O: ImportableObject>( _ object: O, source: O.ImportSource) throwsParameters
objectthe
ImportableObjectto updatesourcethe object to import values from
-
Creates multiple
ImportableObjects by importing from the specified array of import sources.Declaration
Swift
public func importObjects<O: ImportableObject, S: Sequence>( _ into: Into<O>, sourceArray: S) throws -> [O] where S.Iterator.Element == O.ImportSourceParameters
intoan
Intoclause specifying the entity typesourceArraythe array of objects to import values from
Return Value
the array of created
ImportableObjectinstances -
Updates an existing
ImportableUniqueObjector creates a new instance by importing from the specified import source.Declaration
Swift
public func importUniqueObject<O: ImportableUniqueObject>( _ into: Into<O>, source: O.ImportSource) throws -> O?Parameters
intoan
Intoclause specifying the entity typesourcethe object to import values from
Return Value
the created/updated
ImportableUniqueObjectinstance, ornilif the import was ignored -
Updates existing
ImportableUniqueObjects or creates them by importing from the specified array of import sources.ImportableUniqueObjectmethods are called on the objects in the same order as they are in thesourceArray, and are returned in an array with that same order.Warning
If
sourceArraycontains multiple import sources with same ID, only the lastImportSourceof the duplicates will be imported.Throws
an
Errorthrown from any of theImportableUniqueObjectmethodsDeclaration
Swift
public func importUniqueObjects<O: ImportableUniqueObject, S: Sequence>( _ into: Into<O>, sourceArray: S, preProcess: @escaping (_ mapping: [O.UniqueIDType: O.ImportSource]) throws -> [O.UniqueIDType: O.ImportSource] = { $0 }) throws -> [O] where S.Iterator.Element == O.ImportSourceParameters
intoan
Intoclause specifying the entity typesourceArraythe array of objects to import values from
preProcessa closure that lets the caller tweak the internal
UniqueIDType-to-ImportSourcemapping to be used for importing. Callers can remove from/add to/updatemappingand return the updated array from the closure.Return Value
the array of created/updated
ImportableUniqueObjectinstances
-
Deletes all
DynamicObjects that satisfy the specifiedDeleteClauses. AcceptsWhere,OrderBy, andTweakclauses.Declaration
Swift
@discardableResult public func deleteAll<O>(_ from: From<O>, _ deleteClauses: DeleteClause...) throws -> Int where O : DynamicObjectParameters
froma
Fromclause indicating the entity typedeleteClausesa series of
DeleteClauseinstances for the delete request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the number of
DynamicObjects deleted -
Deletes all
DynamicObjects that satisfy the specifiedDeleteClauses. AcceptsWhere,OrderBy, andTweakclauses.Declaration
Swift
@discardableResult public func deleteAll<O>(_ from: From<O>, _ deleteClauses: [DeleteClause]) throws -> Int where O : DynamicObjectParameters
froma
Fromclause indicating the entity typedeleteClausesa series of
DeleteClauseinstances for the delete request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the number of
DynamicObjects deleted -
Deletes all
DynamicObjects that satisfy the specified conditions.transaction.deleteAll(From<Person>().where(\.age > 50))Declaration
Swift
@discardableResult public func deleteAll<B>(_ clauseChain: B) throws -> Int where B : FetchChainableBuilderTypeParameters
clauseChaina
FetchChainableBuilderTypeclause chain created from aFromclauseReturn Value
the number of
DynamicObjects deleted
-
Fetches the
DynamicObjectinstance in the transaction’s context from a reference created from a transaction or from a different managed object context.Declaration
Swift
public func fetchExisting<O>(_ object: O) -> O? where O : DynamicObjectParameters
objecta reference to the object created/fetched outside the transaction
Return Value
the
DynamicObjectinstance if the object exists in the transaction, ornilif not found. -
Fetches the
DynamicObjectinstance in the transaction’s context from anNSManagedObjectID.Declaration
Swift
public func fetchExisting<O>(_ objectID: NSManagedObjectID) -> O? where O : DynamicObjectParameters
objectIDthe
NSManagedObjectIDfor the objectReturn Value
the
DynamicObjectinstance if the object exists in the transaction, ornilif not found. -
Fetches the
DynamicObjectinstances in the transaction’s context from references created from a transaction or from a different managed object context.Declaration
Swift
public func fetchExisting<O, S>(_ objects: S) -> [O] where O : DynamicObject, O == S.Element, S : SequenceParameters
objectsan array of
DynamicObjects created/fetched outside the transactionReturn Value
the
DynamicObjectarray for objects that exists in the transaction -
Fetches the
DynamicObjectinstances in the transaction’s context from a list ofNSManagedObjectID.Declaration
Swift
public func fetchExisting<O, S>(_ objectIDs: S) -> [O] where O : DynamicObject, S : Sequence, S.Element == NSManagedObjectIDParameters
objectIDsthe
NSManagedObjectIDarray for the objectsReturn Value
the
DynamicObjectarray for objects that exists in the transaction -
Fetches the first
DynamicObjectinstance that satisfies the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> O? where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the first
DynamicObjectinstance that satisfies the specifiedFetchClauses, ornilif no match was found -
Fetches the first
DynamicObjectinstance that satisfies the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> O? where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the first
DynamicObjectinstance that satisfies the specifiedFetchClauses, ornilif no match was found -
Fetches the first
DynamicObjectinstance that satisfies the specifiedFetchChainableBuilderTypebuilt from a chain of clauses.let youngestTeen = transaction.fetchOne( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchOne<B>(_ clauseChain: B) throws -> B.ObjectType? where B : FetchChainableBuilderTypeParameters
clauseChaina
FetchChainableBuilderTypebuilt from a chain of clausesReturn Value
the first
DynamicObjectinstance that satisfies the specifiedFetchChainableBuilderType, ornilif no match was found -
Fetches all
DynamicObjectinstances that satisfy the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [O] where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
all
DynamicObjectinstances that satisfy the specifiedFetchClauses, or an empty array if no match was found -
Fetches all
DynamicObjectinstances that satisfy the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [O] where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
all
DynamicObjectinstances that satisfy the specifiedFetchClauses, or an empty array if no match was found -
Fetches all
DynamicObjectinstances that satisfy the specifiedFetchChainableBuilderTypebuilt from a chain of clauses.let people = transaction.fetchAll( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchAll<B>(_ clauseChain: B) throws -> [B.ObjectType] where B : FetchChainableBuilderTypeParameters
clauseChaina
FetchChainableBuilderTypebuilt from a chain of clausesReturn Value
all
DynamicObjectinstances that satisfy the specifiedFetchChainableBuilderType, or an empty array if no match was found -
Fetches the number of
DynamicObjects that satisfy the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> Int where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the number of
DynamicObjects that satisfy the specifiedFetchClauses -
Fetches the number of
DynamicObjects that satisfy the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> Int where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the number of
DynamicObjects that satisfy the specifiedFetchClauses -
Fetches the number of
DynamicObjects that satisfy the specifiedFetchChainableBuilderTypebuilt from a chain of clauses.let numberOfAdults = transaction.fetchCount( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchCount<B>(_ clauseChain: B) throws -> Int where B : FetchChainableBuilderTypeParameters
clauseChaina
FetchChainableBuilderTypebuilt from a chain of clausesReturn Value
the number of
DynamicObjects that satisfy the specifiedFetchChainableBuilderType -
Fetches the
NSManagedObjectIDfor the firstDynamicObjectthat satisfies the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the
NSManagedObjectIDfor the firstDynamicObjectthat satisfies the specifiedFetchClauses, ornilif no match was found -
Fetches the
NSManagedObjectIDfor the firstDynamicObjectthat satisfies the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the
NSManagedObjectIDfor the firstDynamicObjectthat satisfies the specifiedFetchClauses, ornilif no match was found -
Fetches the
NSManagedObjectIDfor the firstDynamicObjectthat satisfies the specifiedFetchChainableBuilderTypebuilt from a chain of clauses.let youngestTeenID = transaction.fetchObjectID( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchObjectID<B>(_ clauseChain: B) throws -> NSManagedObjectID? where B : FetchChainableBuilderTypeParameters
clauseChaina
FetchChainableBuilderTypebuilt from a chain of clausesReturn Value
the
NSManagedObjectIDfor the firstDynamicObjectthat satisfies the specifiedFetchChainableBuilderType, ornilif no match was found -
Fetches the
NSManagedObjectIDfor allDynamicObjects that satisfy the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the
NSManagedObjectIDfor allDynamicObjects that satisfy the specifiedFetchClauses, or an empty array if no match was found -
Fetches the
NSManagedObjectIDfor allDynamicObjects that satisfy the specifiedFetchClauses. AcceptsWhere,OrderBy, andTweakclauses.Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] where O : DynamicObjectParameters
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for the fetch request. AcceptsWhere,OrderBy, andTweakclauses.Return Value
the
NSManagedObjectIDfor allDynamicObjects that satisfy the specifiedFetchClauses, or an empty array if no match was found -
Fetches the
NSManagedObjectIDfor allDynamicObjects that satisfy the specifiedFetchChainableBuilderTypebuilt from a chain of clauses.let idsOfAdults = transaction.fetchObjectIDs( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func fetchObjectIDs<B>(_ clauseChain: B) throws -> [NSManagedObjectID] where B : FetchChainableBuilderTypeParameters
clauseChaina
FetchChainableBuilderTypebuilt from a chain of clausesReturn Value
the
NSManagedObjectIDfor allDynamicObjects that satisfy the specifiedFetchChainableBuilderType, or an empty array if no match was found
-
Queries aggregate values as specified by the
QueryClauses. Requires at least aSelectclause, and optionalWhere,OrderBy,GroupBy, andTweakclauses.A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func queryValue<O, U>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: QueryClause...) throws -> U? where O : DynamicObject, U : QueryableAttributeTypeParameters
froma
Fromclause indicating the entity typeselectClausea
Select<U>clause indicating the properties to fetch, and with the generic type indicating the return type.queryClausesa series of
QueryClauseinstances for the query request. AcceptsWhere,OrderBy,GroupBy, andTweakclauses.Return Value
the result of the the query, or
nilif no match was found. The type of the return value is specified by the generic type of theSelect<U>parameter. -
Queries aggregate values or aggregates as specified by the
QueryClauses. Requires at least aSelectclause, and optionalWhere,OrderBy,GroupBy, andTweakclauses.A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func queryValue<O, U>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: [QueryClause]) throws -> U? where O : DynamicObject, U : QueryableAttributeTypeParameters
froma
Fromclause indicating the entity typeselectClausea
Select<U>clause indicating the properties to fetch, and with the generic type indicating the return type.queryClausesa series of
QueryClauseinstances for the query request. AcceptsWhere,OrderBy,GroupBy, andTweakclauses.Return Value
the result of the the query, or
nilif no match was found. The type of the return value is specified by the generic type of theSelect<U>parameter. -
Queries a property value or aggregate as specified by the
QueryChainableBuilderTypebuilt from a chain of clauses.A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
let averageAdultAge = transaction.queryValue( From<MyPersonEntity>() .select(Int.self, .average(\.age)) .where(\.age > 18) )Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func queryValue<B>(_ clauseChain: B) throws -> B.ResultType? where B : QueryChainableBuilderType, B.ResultType : QueryableAttributeTypeParameters
clauseChaina
QueryChainableBuilderTypeindicating the property/aggregate to fetch and the series of queries for the request.Return Value
the result of the the query as specified by the
QueryChainableBuilderType, ornilif no match was found. -
Queries a dictionary of attribute values as specified by the
QueryClauses. Requires at least aSelectclause, and optionalWhere,OrderBy,GroupBy, andTweakclauses.A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: QueryClause...) throws -> [[String : Any]] where O : DynamicObjectParameters
froma
Fromclause indicating the entity typeselectClausea
Select<U>clause indicating the properties to fetch, and with the generic type indicating the return type.queryClausesa series of
QueryClauseinstances for the query request. AcceptsWhere,OrderBy,GroupBy, andTweakclauses.Return Value
the result of the the query. The type of the return value is specified by the generic type of the
Select<U>parameter. -
Queries a dictionary of attribute values as specified by the
QueryClauses. Requires at least aSelectclause, and optionalWhere,OrderBy,GroupBy, andTweakclauses.A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: [QueryClause]) throws -> [[String : Any]] where O : DynamicObjectParameters
froma
Fromclause indicating the entity typeselectClausea
Select<U>clause indicating the properties to fetch, and with the generic type indicating the return type.queryClausesa series of
QueryClauseinstances for the query request. AcceptsWhere,OrderBy,GroupBy, andTweakclauses.Return Value
the result of the the query. The type of the return value is specified by the generic type of the
Select<U>parameter. -
Queries a dictionary of attribute values or as specified by the
QueryChainableBuilderTypebuilt from a chain of clauses.A “query” differs from a “fetch” in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
let results = dataStack.queryAttributes( From<MyPersonEntity>() .select( NSDictionary.self, .attribute(\.age, as: "age"), .count(\.age, as: "numberOfPeople") ) .groupBy(\.age) ) for dictionary in results! { let age = dictionary["age"] as! Int let count = dictionary["numberOfPeople"] as! Int print("There are \(count) people who are \(age) years old." }Throws
CoreStoreError.persistentStoreNotFoundif the specified entity could not be found in any store’s schema.Declaration
Swift
public func queryAttributes<B>(_ clauseChain: B) throws -> [[String : Any]] where B : QueryChainableBuilderType, B.ResultType == NSDictionaryParameters
clauseChaina
QueryChainableBuilderTypeindicating the properties to fetch and the series of queries for the request.Return Value
the result of the the query as specified by the
QueryChainableBuilderType
-
The internal
NSManagedObjectContextmanaged by this instance. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.Declaration
Swift
public func unsafeContext() -> NSManagedObjectContext
View on GitHub
BaseDataTransaction Class Reference