SynchronizationManager
public class SynchronizationManager : PersistenceIntegration
Provides the ability to sync content from Contentful to a persistence store.
-
Undocumented
See moreDeclaration
Swift
public enum DBVersions : Int
-
Declaration
Swift
public let name: String -
Declaration
Swift
public var version: String { get } -
Instantiate a new SynchronizationManager.
Declaration
Swift
public init(client: Client? = nil, localizationScheme: LocalizationScheme, persistenceStore: PersistenceStore, persistenceModel: PersistenceModel)Parameters
persistenceStoreThe persistence store to use for storage
matchingAn optional query for syncing specific content, see
Return Value
An initialised instance of SynchronizationManager
-
Undocumented
Declaration
Swift
public convenience init(client: Client? = nil, localizationScheme: LocalizationScheme, persistenceStore: PersistenceStore, persistenceModel: PersistenceModel, preseedConfig: PreseedConfiguration, preseedStrategy: PreseedStrategy = FilePreseedManager()) throws -
Declaration
Swift
public func update(localeCodes: [LocaleCode]) -
sync(syncSpacePersistable:initialLocalizationScheme: limit: dbVersion: onInitialCompletion: onFinalCompletion: ) Synchronizes data using the provided localization scheme, performing a follow-up sync with all localizations if required.
Throws
An assertion failure if
initialLocalizationSchemeis.all.The synchronization process involves two phases:
- Synchronizing data with the provided localization scheme.
- Resetting the synchronization token and synchronizing with
.alllocalizations. TheonInitialCompletionclosure is invoked after the first phase, and the final result is passed to theonFinalCompletionclosure.
Declaration
Swift
public func sync<SSP>( syncSpacePersistable: SSP.Type, initialLocalizationScheme: LocalizationScheme, limit: Int? = nil, dbVersion: Int = DBVersions.default.rawValue, onInitialCompletion: @escaping ResultsHandler<SyncSpace>, onFinalCompletion: @escaping ResultsHandler<SyncSpace> ) throws where SSP: SyncSpacePersistableParameters
syncSpacePersistableThe type conforming to
SyncSpacePersistableused for handling synchronization data.initialLocalizationSchemeThe localization scheme to use for the initial synchronization phase. This must not be
.all.limitAn optional limit for the number of records to synchronize in one batch. Defaults to
nil, indicating no limit.dbVersionThe database version targeted for synchronization. Defaults to the application’s default database version.
onInitialCompletionA closure called upon completion of the initial synchronization phase, with a
Resultcontaining either theSyncSpaceor an error.onFinalCompletionA closure called upon completion of the final synchronization phase, with a
Resultcontaining either theSyncSpaceor an error. -
A wrapper method to synchronize data from Contentful to your local data store. The callback for this method is thread safe and will delegate to the thread that your data store is tied to.
Execute queries on your local data store in the callback for this method.
Declaration
Swift
public func sync(limit: Int? = nil, dbVersion: Int = DBVersions.default.rawValue, then completion: @escaping ResultsHandler<SyncSpace>)Parameters
limitNumber of elements per page. See documentation for details.
-
The Contentful.Client that is configured to retrieve data from your Contentful space.
Declaration
Swift
public var client: Client? -
The localization scheme with which to synchronize your Contentful space to your data store.
Declaration
Swift
public var localizationScheme: LocalizationScheme -
Undocumented
Declaration
Swift
public var syncToken: String? { get } -
Undocumented
Declaration
Swift
public func performAndWait(block: @escaping () -> Void) -
Declaration
Swift
public func update(with syncSpace: SyncSpace) -
Declaration
Swift
public func update(syncToken: String) -
Declaration
Swift
public func resolveRelationships()
-
This function is public as a side-effect of implementing
PersistenceDelegate.Declaration
Swift
public func create(asset: Asset)Parameters
assetThe newly created Asset
-
Never call this directly. This function is public as a side-effect of implementing
SyncSpaceDelegate.Declaration
Swift
public func create(entry: Entry) -
This function is public as a side-effect of implementing
PersistenceDelegate.Declaration
Swift
public func delete(assetWithId: String)Parameters
assetIdThe ID of the deleted Asset
-
This function is public as a side-effect of implementing
SyncSpaceDelegate.Declaration
Swift
public func delete(entryWithId: String)Parameters
entryIdThe ID of the deleted Entry
-
Declaration
Swift
public func save()
-
The local URL where unresolved relationships are cached so that they may be resolved on future app launches. Useful for debugging.
Declaration
Swift
public var pendingRelationshipsURL: URL? { get } -
The unsresolved relationships that were cached to disk.
Declaration
Swift
public var cachedUnresolvedRelationships: [String : [FieldName : Any]]? { get } -
This method will seed a CoreData datastore from a directory of JSON files in the specified Bundle. Use this method in conjunction with the ContentfulBundleSync command line interface.
Throws
Errors if the media the files in the directory can’t be deserialized.
Declaration
Swift
func seedDBFromJSONFiles(in directory: String, in bundle: Bundle) throwsParameters
directoryThe name of the directory in your bundle which contains your Contentful JSON and media assets generated by the CLI.
bundleThe bundle in which your directory containing your Contentful data is located.
-
Returns the local path for media assets that have been bundled in your app’s bundle for the passed in
AssetorAssetPersistable. This only works if you’ve used the ContentfulBundleSync command line tool.Declaration
Swift
static func pathInBundle(for media: AssetProtocol, inDirectoryNamed directory: String, in bundle: Bundle) -> String?Parameters
mediaThe Asset or AssetPersistable for which on-disk data should be retreived.
directoryThe name of the directory in your bundle which contains the media data
bundleThe bundle in which your directory containing your media files is located.
Return Value
The full string path for the underlying media file associated with the passed in
AssetorAssetPersistabl. Will returnnilif no directory exists at your directory name, or if theMediadoes not have a validurlStringassociated with it. -
Returns on-disk data that is bundled in your app’s bundle for the passed in
AssetorAssetPersistable. This only works if you’ve used the ContentfulBundleSync command line tool.Declaration
Swift
static func bundledData(for media: AssetProtocol, inDirectoryNamed directory: String, in bundle: Bundle) -> Data?Parameters
mediaThe Asset or AssetPersistable for which on-disk data should be retreived.
directoryThe name of the directory in your bundle which contains the media data
bundleThe bundle in which your directory containing your media files is located.
Return Value
The
Dataobject for your media file. Will returnnilif no directory exists at your directory name, or if theMediadoes not have aurlStringassociated with it. -
Returns a file name to be used for local storage given a passed in
AssetorAssetPersistable.Declaration
Swift
static func fileName(for media: AssetProtocol) -> String?Parameters
mediaThe Asset or AssetPersistable for which a file name should be computed.
Return Value
A filename for the underlying media file. Will return
nilif the Asset or AssetPersistable does not have aurlStringassociated with it. -
Errors thrown by ContentfulPersistence when trying to seed a database with bundled data.
See moreDeclaration
Swift
enum DatabaseSeedingError : Swift.Error, CustomDebugStringConvertible
View on GitHub
SynchronizationManager Class Reference