Receive JSON object in Swift Socket.IO Client
<p>How can I receive a JSON object in the <a href="http://socket.io/blog/socket-io-on-ios/#" rel="nofollow">Swift Socket.IO</a> client?</p>

<p><strong>Node.js</strong></p>

<p>From socket.io on Node.js, I emit a json object as in this simplified example:</p>

<pre><code>socket.emit('welcome', { text : 'Hello, World!' });
</code></pre>

<p><strong>Swift</strong></p>

<p>In an iOS Swift client, I would like to get this message out of the object.</p>

<pre><code>socket?.on("welcome") {[weak self] data, ack in
    print(data)
    if let msg = data[0] as? String {
        print(msg) // never prints; something's wrong
    }
}
</code></pre>

<p>The value of <code>data</code> when I print it out is:</p>

<pre><code>[{
    text = "Hello, World!";
}]
</code></pre>

<p>When I attempt to parse <code>data[0]</code> with the following (from the <a href="https://developer.apple.com/swift/blog/?id=37" rel="nofollow">Apple Developer Blog</a>)...</p>

<pre><code>let json = try? JSONSerialization.jsonObject(with: data[0], options: [])
</code></pre>

<p>...I am met with an error message:</p>

<blockquote>
  <p>Cannot invoke 'jsonObject' with argument list of type '(with: Any, options: [Any])'</p>
</blockquote>