Skip to content

convert a JSONCodable object to JSONCodableScalar #96

@shanilevink

Description

@shanilevink

Hi,
I am trying to convert a JSONCodable object to a JSONCodableScalar and this is failing. the object itself is a representation of json data (with nested values as well). how can I make this work in order to set my presence state, I fail in the second guard statement

`
func setState(stateCodable: JsonCodable) {

    let encoder = JSONEncoder()
    guard let data = try? encoder.encode(stateCodable) else {
        return
    }
    guard let state = try? JSONSerialization.jsonObject(with: data) as? [String: JSONCodableScalar] else {
        return
    }
    pubnub.setPresence(
        state: state,
        on: ["channel"]
    ) { result in
        switch result {
        case let .success(response):
          print("Successful Set State Response: \(response)")
        case let .failure(error):
          print("Failed Set State Response: \(error.localizedDescription)")
        }
    }
}

`
thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions