-
addStorage(_:Asynchronous) Swift concurrency extension for
CoreStore.DataStack‘saddStorage(...)API. Asynchronously adds aStorageInterfaceto the stack.let storage = try await dataStack.async.addStorage( InMemoryStore(configuration: "Config1") )Throws
ACoreStoreErrorvalue indicating the failure reasonDeclaration
Swift
public func addStorage<T: StorageInterface>( _ storage: T ) async throws -> TParameters
storagethe storage
Return Value
The
StorageInterfaceinstance added to theDataStack. Note that theStorageInterfaceevent value may not always be the same instance as the parameter argument if a previousStorageInterfacewas already added at the same URL and with the same configuration. -
Swift concurrency extension for
CoreStore.DataStack‘saddStorage(...)API. Asynchronously adds aLocalStorageto the stack. Migrations are also initiated by default. The event emitsMigrationProgressenumvalues.for try await migrationProgress in dataStack.async.addStorage( SQLiteStore( fileName: "core_data.sqlite", configuration: "Config1" ) ) { print("\(round(migrationProgress.fractionCompleted * 100)) %") // 0.0 ~ 1.0 }Throws
ACoreStoreErrorvalue indicating the failure reasonDeclaration
Swift
public func addStorage<T>( _ storage: T ) -> AsyncThrowingStream<MigrationProgress<T>, Swift.Error>Parameters
storagethe local storage
Return Value
An
AsyncThrowingStreamthat emits aMigrationProgressvalue with metadata for migration progress. Note that theLocalStorageevent value may not always be the same instance as the parameter argument if a previousLocalStoragewas already added at the same URL and with the same configuration. -
importObject(_:Asynchronoussource: ) Swift concurrency extension for
CoreStore.DataStack‘simportObject(...)API. Creates anImportableObjectby importing from the specified import source. The event value will be the object instance correctly associated for theDataStack.let object = try await dataStack.async.importObject( Into<Person>(), source: ["name": "John"] )Throws
ACoreStoreErrorvalue indicating the failure reasonDeclaration
Swift
public func importObject<O: DynamicObject & ImportableObject>( _ into: Into<O>, source: O.ImportSource ) async throws -> O?Parameters
intoan
Intoclause specifying the entity typesourcethe object to import values from
Return Value
The object instance correctly associated for the
DataStackif the object was imported successfully, ornilif theImportableObjectignored thesource. -
importObject(_:Asynchronoussource: ) Swift concurrency extension for
CoreStore.DataStack‘simportObject(...)API. Updates an existingImportableObjectby importing values from the specified import source. The event value will be the object instance correctly associated for theDataStack.let importedPerson = try await dataStack.async.importObject( existingPerson, source: ["name": "John", "age": 30] )Throws
ACoreStoreErrorvalue indicating the failure reasonDeclaration
Swift
public func importObject<O: DynamicObject & ImportableObject>( _ object: O, source: O.ImportSource ) async throws -> O?Parameters
objectthe object to update
sourcethe object to import values from
Return Value
The object instance correctly associated for the
DataStackif the object was imported successfully, ornilif theImportableObjectignored thesource. -
importUniqueObject(_:Asynchronoussource: ) Swift concurrency extension for
CoreStore.DataStack‘simportUniqueObject(...)API. Updates an existingImportableUniqueObjector creates a new instance by importing from the specified import source. The event value will be the object instance correctly associated for theDataStack.let person = try await dataStack.async.importUniqueObject( Into<Person>(), source: ["name": "John", "age": 30] )Throws
ACoreStoreErrorvalue indicating the failure reasonDeclaration
Swift
public func importUniqueObject<O: DynamicObject & ImportableUniqueObject>( _ into: Into<O>, source: O.ImportSource ) async throws -> O?Parameters
intoan
Intoclause specifying the entity typesourcethe object to import values from
Return Value
The object instance correctly associated for the
DataStackif the object was imported successfully, ornilif theImportableUniqueObjectignored thesource. -
importUniqueObjects(_:AsynchronoussourceArray: preProcess: ) Swift concurrency extension for
CoreStore.DataStack‘simportUniqueObjects(...)API. Updates existingImportableUniqueObjects 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. The event values will be object instances correctly associated for theDataStack.let people = try await dataStack.async.importUniqueObjects( Into<Person>(), sourceArray: [ ["name": "John"], ["name": "Bob"], ["name": "Joe"] ] )Warning
IfsourceArraycontains multiple import sources with same ID, no merging will occur and ONLY THE LAST duplicate will be imported.Throws
ACoreStoreErrorvalue indicating the failure reasonDeclaration
Swift
public func importUniqueObjects<O: DynamicObject & ImportableUniqueObject, S: Sequence>( _ into: Into<O>, sourceArray: S, preProcess: @escaping (_ mapping: [O.UniqueIDType: O.ImportSource]) throws -> [O.UniqueIDType: O.ImportSource] = { $0 } ) async 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 imported objects correctly associated for the
DataStack. -
perform(_:Asynchronous) Swift concurrency extension for
CoreStore.DataStack‘sperform(asynchronous:...)API. Performs a transaction asynchronously whereNSManagedObjectcreates, updates, and deletes can be made. The changes are commited automatically after thetaskclosure returns. The event value will be the value returned from thetaskclosure. Any errors thrown from inside thetaskwill be wrapped in aCoreStoreErrorbefore being thrown from theasyncmethod. To cancel/rollback changes, calltransaction.cancel(), which throws aCoreStoreError.userCancelled.let result = try await dataStack.async.perform( asynchronous: { (transaction) -> (inserted: Set<NSManagedObject>, deleted: Set<NSManagedObject>) in // ... return ( transaction.insertedObjects(), transaction.deletedObjects() ) } ) let inserted = dataStack.fetchExisting(result.inserted) let deleted = dataStack.fetchExisting(result.deleted)Throws
ACoreStoreErrorvalue indicating the failure reasonDeclaration
Swift
public func perform<Output>( _ asynchronous: @escaping (AsynchronousDataTransaction) throws -> Output ) async throws -> OutputParameters
taskthe asynchronous closure where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent
NSManagedObjectContext.Return Value
The value returned from the
taskclosure.
View on GitHub
AsyncNamespace Structure Reference