Invoking the Insights for Twitter Service in Bluemix from Swift

Hear the Buzz” is a sample iPhone app which finds tweets with positive or negative sentiments for certain topics via the IBM Insights for Twitter service in IBM Bluemix. Below is a short description how this service is used from Swift.

As a starting point I used the sample app from my colleague Frederic Lavigne. The sample contains a simple Node.js application which provides a REST API that basically just forwards requests to the service and adds credentials so that clients can invoke the API without having to authenticate. I used this mechanism in this simple sample but you might want to change this for production apps.

Clients can now invoke REST APIs via which returns JSON. The following code shows how I parse the JSON is Swift. There might be better ways to do this though. I haven’t done much Swift development honestly.

The next screenshot shows the code how to invoke the REST API from Swift. In order to define the tweets I’m interested in I use the query language of the Twitter service.