OfflineClient

@objcMembers
public class OfflineClient : Client

An API client that adds offline features on top of the regular online API client.

Note

Requires Algolia’s Offline Core SDK. The enableOfflineMode(...) method must be called with a valid license key prior to calling any offline-related method.
  • Path to directory where the local data is stored. Defaults to an algolia sub-directory inside the Library/Application Support directory. If you set it to another value, do so before calling enableOfflineMode(...).

    Warning

    This directory will be explicitly excluded from iCloud/iTunes backup.

    Declaration

    Swift

    @objc
    public var rootDataDir: String
  • Create a new offline-capable Algolia Search client.

    Note

    Offline mode is disabled by default, until you call enableOfflineMode(...).

    Declaration

    Swift

    @objc
    public override init(appID: String, apiKey: String)

    Parameters

    appID

    the application ID you have in your admin interface

    apiKey

    a valid API key for the service

  • Enable the offline mode.

    Declaration

    Swift

    @objc(enableOfflineModeWithLicenseKey:)
    public func enableOfflineMode(licenseKey: String)

    Parameters

    licenseKey

    License key for Algolia’s SDK.

  • Obtain a mirrored index.

    Note

    The offline client returns mirror-capable indices.

    Note

    Only one instance can exist for a given index name. Subsequent calls to this method with the same index name will return the same instance, unless it has already been released.

    Warning

    The name should not overlap with any OfflineIndex (see offlineIndex(withName:)).

    Declaration

    Swift

    @objc
    public override func index(withName indexName: String) -> MirroredIndex

    Parameters

    indexName

    The name of the index.

    Return Value

    A proxy to the specified index.

  • Obtain an offline index.

    Note

    Only one instance can exist for a given index name. Subsequent calls to this method with the same index name will return the same instance, unless it has already been released.

    Warning

    The name should not overlap with any MirroredIndex (see index(withName:)).

    Declaration

    Swift

    @objc
    public func offlineIndex(withName indexName: String) -> OfflineIndex

    Parameters

    indexName

    The name of the index.

    Return Value

    A proxy to the specified index.

  • Test if an index has offline data on disk.

    Note

    This applies both to MirroredIndex and OfflineIndex instances.

    Warning

    This method is synchronous!

    Declaration

    Swift

    @objc
    public func hasOfflineData(indexName: String) -> Bool

    Parameters

    indexName

    The index’s name.

    Return Value

    true if data exists on disk for this index, false otherwise.

  • List existing offline indexes. Only indices that actually exist on disk are listed. If an instance was created but never synced or written to, it will not appear in the list.

    Note

    This applies both to MirroredIndex and OfflineIndex instances.

    Declaration

    Swift

    @discardableResult
    @objc(listOfflineIndexes:)
    public func listOfflineIndexes(completionHandler: @escaping CompletionHandler) -> Operation

    Parameters

    completionHandler

    Completion handler to be notified of the request’s outcome.

    Return Value

    A cancellable operation.

  • Delete an offline index.

    Note

    This applies both to MirroredIndex and OfflineIndex instances.

    Declaration

    Swift

    @discardableResult
    @objc(deleteOfflineIndexWithName:completionHandler:)
    public func deleteOfflineIndex(withName indexName: String, completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    indexName

    Name of the index to delete.

    completionHandler

    Completion handler to be notified of the request’s outcome.

    Return Value

    A cancellable operation.

  • Move an existing index.

    Warning

    This will overwrite the destination index if it exists.

    Note

    This applies both to MirroredIndex and OfflineIndex instances.

    Declaration

    Swift

    @discardableResult
    @objc
    public func moveOfflineIndex(from srcIndexName: String, to dstIndexName: String, completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    srcIndexName

    Name of index to move.

    dstIndexName

    The new index name.

    completionHandler

    Completion handler to be notified of the request’s outcome.

    Return Value

    A cancellable operation.