Structures
The following structures are available globally.
-
The
Tweakclause allows fine-tuning theNSFetchRequestfor a fetch or query. Sample usage:
See morelet employees = transaction.fetchAll( From<MyPersonEntity>(), Tweak { (fetchRequest) -> Void in fetchRequest.includesPendingChanges = false fetchRequest.fetchLimit = 5 } )Declaration
Swift
public struct Tweak : FetchClause, QueryClause, DeleteClause
-
The
See moreCloudStorageOptionsprovides settings that tells theDataStackhow to setup the persistent store forLocalStorageimplementers.Declaration
Swift
public struct CloudStorageOptions : OptionSet, ExpressibleByNilLiteral
-
A
Fromclause specifies the source entity and source persistent store for fetch and query methods. A common usage is to just indicate the entity:let person = transaction.fetchOne(From<Person>())For cases where multiple
NSPersistentStores contain the same entity, the source configuration’s name needs to be specified as well:
See morelet person = transaction.fetchOne(From<Person>("Configuration1"))Declaration
Swift
public struct From<D> where D : DynamicObject
-
The
See moreGroupByclause specifies that the result of a query be grouped accoording to the specified key path.Declaration
Swift
public struct GroupBy<D> : GroupByClause, QueryClause, Hashable where D : DynamicObject
-
An
Intoclause contains the destination entity and destination persistent store for acreate(...)method. A common usage is to just indicate the entity:let person = transaction.create(Into<MyPersonEntity>())For cases where multiple
NSPersistentStores contain the same entity, the destination configuration’s name needs to be specified as well:
See morelet person = transaction.create(Into<MyPersonEntity>("Configuration1"))Declaration
Swift
public struct Into<D> : Hashable where D : DynamicObject
-
The
See moreLocalStorageOptionsprovides settings that tells theDataStackhow to setup the persistent store forLocalStorageimplementers.Declaration
Swift
public struct LocalStorageOptions : OptionSet, ExpressibleByNilLiteral
-
A
MigrationChainindicates the sequence of model versions to be used as the order for progressive migrations. This is typically passed to theSchemaHistoryor theDataStackinitializer and will be applied to all stores added to theDataStackwithaddStorage(...)and its variants.Initializing with empty values (either
nil,[], or[:]) instructs theDataStackto use the .xcdatamodel’s current version as the final version, and to disable progressive migrations:let dataStack = DataStack(migrationChain: nil)This means that the mapping model will be computed from the store’s version straight to the
DataStack‘s model version. To support progressive migrations, specify the linear order of versions:let dataStack = DataStack(migrationChain: ["MyAppModel", "MyAppModelV2", "MyAppModelV3", "MyAppModelV4"])or for more complex migration paths, a version tree that maps the key-values to the source-destination versions:
let dataStack = DataStack(migrationChain: [ "MyAppModel": "MyAppModelV3", "MyAppModelV2": "MyAppModelV4", "MyAppModelV3": "MyAppModelV4" ])This allows for different migration paths depending on the starting version. The example above resolves to the following paths:
- MyAppModel-MyAppModelV3-MyAppModelV4
- MyAppModelV2-MyAppModelV4
- MyAppModelV3-MyAppModelV4
The
MigrationChainis validated when passed to theDataStackand unless it is empty, will raise an assertion if any of the following conditions are met:- a version appears twice in an array
- a version appears twice as a key in a dictionary literal
- a loop is found in any of the paths
Declaration
Swift
public struct MigrationChain : ExpressibleByNilLiteral, ExpressibleByStringLiteral, ExpressibleByDictionaryLiteral, ExpressibleByArrayLiteral, Equatable
-
The
See moreOrderByclause specifies the sort order for results for a fetch or a query.Declaration
Swift
public struct OrderBy<D> : OrderByClause, FetchClause, QueryClause, DeleteClause, Hashable where D : DynamicObject
-
A
See morePartialObjectis only used when overriding getters and setters forCoreStoreObjectproperties. Custom getters and setters are implemented as a closure thatoverrides
the default property getter/setter. The closure receives aPartialObject<O>, which acts as a fast, type-safe KVC interface forCoreStoreObject. The reason aCoreStoreObjectinstance is not passed directly is because the Core Data runtime is not aware ofCoreStoreObjectproperties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a heavy performance hit (especially in KVO-heavy operations such asListMonitorobserving.) When accessing the property value fromPartialObject<O>, make sure to usePartialObject<O>.persistentValue(for:)instead ofPartialObject<O>.value(for:), which would unintentionally execute the same closure again recursively.Declaration
Swift
public struct PartialObject<O> where O : CoreStoreObject
-
The
SectionByclause indicates the key path to use to group theListMonitorobjects into sections. An optional closure can also be provided to transform the value into an appropriate section name:
See morelet monitor = CoreStore.monitorSectionedList( From<Person>(), SectionBy("age") { "Age \($0)" }, OrderBy(.ascending("lastName")) )Declaration
Swift
@available(OSX 10.12, *) public struct SectionBy<D> where D : DynamicObject
-
The
Selectclause indicates the attribute / aggregate value to be queried. The generic type is aSelectResultType, and will be used as the return type for the query.You can bind the return type by specializing the initializer:
let maximumAge = CoreStore.queryValue( From<MyPersonEntity>(), Select<Int>(.maximum("age")) )or by casting the type of the return value:
let maximumAge: Int = CoreStore.queryValue( From<MyPersonEntity>(), Select(.maximum("age")) )Valid return types depend on the query:
- for
queryValue(...)methods:- all types that conform to
QueryableAttributeTypeprotocol
- all types that conform to
for
queryAttributes(...)methods:NSDictionary
Declaration
Swift
public struct Select<D, T> : SelectClause, Hashable where D : DynamicObject, T : SelectResultTypeParameters
sortDescriptorsa series of
NSSortDescriptors - for
-
The
See moreWhereclause specifies the conditions for a fetch or a query.Declaration
Swift
public struct Where<D> : WhereClauseType, FetchClause, QueryClause, DeleteClause, Hashable where D : DynamicObject
-
The
VersionLockcontains the version hashes for entities. This is then passed to theCoreStoreSchema, which contains all entities for the store. An assertion will be raised if anyEntitydoesn’t match the version hash.
See moreclass Animal: CoreStoreObject { let species = Value.Required<String>("species", initial: "") let nickname = Value.Optional<String>("nickname") let master = Relationship.ToOne<Person>("master") } class Person: CoreStoreObject { let name = Value.Required<String>("name", initial: "") let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master }) } CoreStore.defaultStack = DataStack( CoreStoreSchema( modelVersion: "V1", entities: [ Entity<Animal>("Animal"), Entity<Person>("Person") ], versionLock: [ "Animal": [0x2698c812ebbc3b97, 0x751e3fa3f04cf9, 0x51fd460d3babc82, 0x92b4ba735b5a3053], "Person": [0xae4060a59f990ef0, 0x8ac83a6e1411c130, 0xa29fea58e2e38ab6, 0x2071bb7e33d77887] ] ) )Declaration
Swift
public struct VersionLock : ExpressibleByDictionaryLiteral, Equatable
-
The fetch builder type used for fetches. A
FetchChainBuilderis created from aFromclause.
See morelet people = source.fetchAll( From<MyPersonEntity>() .where(\.age > 18) .orderBy(.ascending(\.age)) )Declaration
Swift
public struct FetchChainBuilder<D> : FetchChainableBuilderType where D : DynamicObject
-
The fetch builder type used for a queries. A
QueryChainBuilderis created from aFromclause and then aselect(...)chain.
See morelet averageAdultAge = dataStack.queryValue( From<MyPersonEntity>() .select(Int.self, .average(\.age)) .where(\.age > 18) )Declaration
Swift
public struct QueryChainBuilder<D, R> : QueryChainableBuilderType where D : DynamicObject, R : SelectResultType
-
The fetch builder type used for a sectioned
ListMonitor. ASectionMonitorChainBuilderis created from aFromclause and then asectionBy(...)chain.
See morelet monitor = transaction.monitorSectionedList( From<MyPersonEntity>() .sectionBy(\.age, { "\($0!) years old" }) .where(\.age > 18) .orderBy(.ascending(\.age)) )Declaration
Swift
@available(OSX 10.12, *) public struct SectionMonitorChainBuilder<D> : SectionMonitorBuilderType where D : DynamicObject
View on GitHub
Structures Reference