Can't get Metadata


I am trying to create a flutter wrapper for Sendbird and being a complete beginner to Swift I am struggling. The function I am running is as follows:

static func extractChannel( channel: SBDBaseChannel, js: inout NSMutableDictionary 
    js["cover_url"] = channel.coverUrl
    js["name"] =
    js["url"] = channel.channelUrl
    js["data"] =
    js["is_open_channel"] = channel.isOpen()
    var channelMetadata = [String: Any]()
    channel.getAllMetaData{ (metaData, error) in
         guard let metadata = metaData, error == nil else {   // Error.
        channelMetadata = metadata
      js["status"] = channelMetadata["status"]
    switch channel{
    case let opench as SBDOpenChannel:
        js["custom_type"] = opench.customType
    case let groupch as SBDGroupChannel:
        js["is_public"] = groupch.isPublic
        js["custom_type"] = groupch.customType
        js["unread_message_count"] = groupch.unreadMessageCount

        var msg = NSMutableDictionary()
        if( groupch.lastMessage != nil ) {
            extractMessage( msg: groupch.lastMessage!, js: &msg )
        js["last_message"] = msg
        let members = NSMutableArray()
        if( groupch.members != nil ) {
            for member in (groupch.members as! [SBDMember] ){
             let jsmem = NSMutableDictionary()
             jsmem["nickname"] = member.nickname
             jsmem["user_id"] = member.userId
             jsmem["profile_url"] = member.profileUrl
        js["members"] = members
        let readlist = NSMutableDictionary()
        let readInfo = groupch.getReadStatus(includingAllMembers: true)
        // 'getReadStatus' Function may deprecated
        for (k, info) in readInfo {
            let jsinfo = info as NSDictionary
            readlist[k] = jsinfo["last_seen_at"]
        js["read_status"] = readlist
        NSLog("channel extract error")

However, when I try to retrieve the value of the “status” key it always returns null, even though I know that the key has a value.

I have searched for a solution for ages ages and tried many different approaches, but to no avail. What am I doing wrong? Any help would be much appreciated!

Hey @Nicholas_Latham are you saying the “status” key is null on channelMetaData? Do you mind telling me what SDK you are working off of?

Hi Alex, I am working with the Sendbird-iOS SDK. I am forking an existing “flutter wrapper” project for Sendbird which seems to do most of what I want:

however it doesn’t extract Channel Metadata.

My hunch is that because getAllMetaData is async the call doesn’t complete before I do js["status"] = channelMetadata["status"] so channelMetadata["status"] is empty. As I said I am a complete beginner with Swift and despite trying many things (e.g. DispatchGroup()) it always returns null

@Nicholas_Latham, I meant what SDK version sorry. But that isn’t needed. Ahh yea you are right. So there is a chance that the callback from getAllMetaData hasn’t returned yet. In fact, I would assume based on the call:

js["status"] = channelMetadata["status"]

and its place meant outside the callback, that the value of channelMetadata['status'] would be null. I think you should wait for the assignment until you get the response of the getAllMetaData call.