Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert a JSONCodable object to JSONCodableScalar #96

Open
shanilevink opened this issue Feb 8, 2022 · 0 comments
Open

convert a JSONCodable object to JSONCodableScalar #96

shanilevink opened this issue Feb 8, 2022 · 0 comments

Comments

@shanilevink
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant