nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Use "data[0]" object in handler #104

Closed OptimusKoala closed 8 years ago

OptimusKoala commented 8 years ago

How can I use the "data" object into handler to get values into String ?

Part of my code. The print return many values like : "id = 4, gender = male, ..."

socket.on("select") {data, ack in
print(data[0])
}

I've tried to use the data object like an array but it fails.

OptimusKoala commented 8 years ago

I've found my answer, I use SwiftyJSON and this code.

 func userSelectHandler() {
        socket.on("select") {data, ack in
            let jsonData = JSON(data)
            print(jsonData[0]["email"].stringValue)
        }
    }