DXDataClient

This class is responsible for making requests to the DX data API.

public final class DXDataClient

The DXDataClient class allows you to create and update buckets to store your app's data. Buckets can be created for a single user for private data. or for multiple users, allowing them to access shared data. Buckets are essentially JSON objects with key-value pairs and can be updated by creating and writing to a new key, or overwriting an existing one.

You will need to enable the "Lightning Database" scope for your app in the developer dashboard before using the data API.

Properties

public static let shared: DXDataClient

Singleton instance of DXDataClient. You will access all the available DXDataClient methods through this instance.

Methods

readPrivateData

public func readPrivateData(
    userId: String? = nil, 
    completion: @escaping (_ error: Error?, _ data: Any?) -> Void
) -> Void

Read a user's private app data.

writePrivateData

public func writePrivateData<V: Codable>(
    atKey key: String, 
    withValue value: V, 
    userId: String? = nil, 
    _  completion: ((_ error: Error?, _ data: Any?) -> Void)?
) -> Void

Update a user's private app data.

create

public func create(
    bucketNamed bucketName: String, 
    includingUsers users: [String] = [], 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

Create a named bucket and specify what users have access to it. By default, the user creating the bucket (the currently authenticated user) will have access to the bucket.

write

public func write<V: Codable>(
    toBucket bucketName: String, 
    atKey key: String, 
    withValue value: V, 
    _  completion: ((_ error: Error?, _ data: Any?) -> Void)?
) -> Void

Write data to a bucket at a key. If key is an empty String, the bucket will be overwritten with the value provided. If the key does not exist in the bucket, it will be created in the bucket as a key-value pair. All data written to a bucket has to conform to Swift's Codable protocol (introduced in version 4.2), as it will otherwise cause an error when attempting to serialize the value to JSON. For more information on Codable, check out this link.

Attempting to write to a bucket that hasn't been created will return an error.

read

public func read(
    fromBucket bucketName: String, 
    atKey key: String? = nil, 
    _ completion: @escaping (_ error: Error?, _ value: Any?) -> Void
) -> Void

Read data from a bucket. If a key is provided, it will read data from that key in the bucket.

Attempting to read from a bucket that hasn't been created will return an error.

readAllBuckets

public func readAllBuckets(
    _ completion: @escaping (_ error: Error?, _ buckets: [String]?) -> Void
) -> Void

Read all buckets that the current user has access to. Will return an array of the buckets' names.

delete

public func delete(
    fromBucket bucketName: String, 
    atKey key: String, 
    _ completion: ((_ error: Error?, _ bucket: Any?) -> Void)?
) -> Void

Delete a key in the bucket, including all nested data at that key.

Attempting to delete a key in a bucket that hasn't been created will return an error.

delete

public func delete(
    bucketNamed bucketName: String, 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

Delete an entire bucket.

Attempting to delete a bucket that hasn't been created will return an error.

Last updated