iOS
User Metadata

User Metadata

With a user metadata, you can store additional information to a user. Use cases for the metadata are such as a phone number, a long description or an email of the user, which can each be fetched and rendered into the UI.


Create, update, retrieve, and delete a user metadata

A user metadata is a NSDictionary<NSString *, NSString *> that you can store into a SBDUser object. Its uses are flexible, allowing you to customize a channel to fit you and your users' needs.

Create

To store a metadata into a user, create a NSDictionary<NSString *, NSString *>, add key-value pairs to it, and then pass it as a parameter when calling the createMetaData:completionHandler: method. You can store multiple key-value pairs in the dictionary.

Objective-C
Swift
Light Color Skin
Copy
SBDUser *user = [SBDMain getCurrentUser];

NSDictionary *data = @{@"key1": @"value1",
        @"key2": @"vaule2"};

[user createMetaData:data completionHandler:^(NSDictionary<NSString *,NSString *> * _Nullable metaData, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
let user = SBDMain.getCurrentUser()!

let data = [
    "key1": "value1",
    "key2": "value2"
]

user.createMetaData(data) { (metaData, error) in
    guard error == nil else {   // Error.
        return
    }
}

Update

The process for updating a user metadata is identical with the creation. Values are updated for existing keys, while new key-value pairs added.

Objective-C
Swift
Light Color Skin
Copy
SBDUser *user = [SBDMain getCurrentUser];

NSDictionary *data = @{@"key1": @"valueToUpdate1",
        @"key2": @"valueToUpdate2"};

[user updateMetaData:data completionHandler:^(NSDictionary<NSString *,NSString *> * _Nullable metaData, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
let user = SBDMain.getCurrentUser()!

let data = [
    "key1": "valueToUpdate1",
    "key2": "valueToUpdate2"
]

user.updateMetaData(data) { (metaData, error) in
    guard error == nil else {   // Error.
        return
    }
}

Retrieve

To get stored key-value pairs in a user metadata, read the metadata property of a SBDUser object.

Objective-C
Swift
Light Color Skin
Copy
SBDUser *user = [SBDMain getCurrentUser];
NSDictionary *metaData = user.metaData;
Light Color Skin
Copy
let user = SBDMain.getCurrentUser()!
let metaData = user.metaData

Delete

The process for deleting a user metadata is as simple as creating one.

Objective-C
Swift
Light Color Skin
Copy
SBDUser *user = [SBDMain getCurrentUser];

[user deleteMetaDataWithKey:@"key1" completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
let user = SBDMain.getCurrentUser()!

user.deleteMetaData(withKey: "key1") { (error) in
    guard error == nil else {   // Error. 
        return
    }
}