Search code examples
iosswiftchatgetstream-io

How to access custom channel extra data from iOS client


Currently our backend has added a dict on channel object as part of the extra data, it looks something like this:

{
  // channel stuff from Stream
  "extra_data": {
    "custom dict": {
      "custom field": "custom value"
    }
  }
}

However it seems that we cannot access to that dict from the iOS client since the channel.extraData type is a ChannelExtraDataCodable which only has two properties: name and imageURL.

Is there a way to access to this custom stuff from the client side?

Thanks in advance.


Solution

  • You need to define your own structure conforming to ChannelExtraDataCodable and set Channel.extraDataType to it.

    Example:

    struct MyChannelExtraData: ChannelExtraDataCodable {
        var name: String?
        var imageURL: URL?
        var customDict: [String: String]
    }
    
    // Before you initialize the client
    Channel.extraDataType = MyChannelExtraData.self
    

    For more information on this, you can check the Stream Chat's documentation about custom extra data on iOS.