After spending a long time in beta, the Swift SDK for IBM Watson is now officially released! This SDK provides an easy, intuitive way to integrate Watson’s AI platform into your iOS apps or Swift servers on Linux. Although you can access the Watson APIs with standard REST requests, this SDK abstracts away all of the underlying HTTP infrastructure (including authentication and JSON encoding/decoding), so that you can communicate directly with Watson services in a more “swifty” way.
Here is the list of services that the Swift SDK supports right now.
Setting up and installing
First, provision the services that you want to use on the IBM Cloud. For this example, let’s use Tone Analyzer to understand the emotional and social context of what your users are saying. After you’ve created your service instance, a set of credentials is created for you.
Next, import the service at the top of your source files. The import statement differs depending on which dependency management tool you used.
- Swift Package Manager:
Now, create an instance of the service you want to use:
Substitute the values for
toneAnalyzer.serviceURL using the API Key and URL obtained from the service instance you created (see the earlier screenshot for reference). The
version parameter specifies the minor version of the backend API, which is explained further in the API reference.
Using the APIs
Now comes the fun part! You can use the instance of the Watson service created in the previous step to call any of the supported API methods. Let’s use our ToneAnalyzer service to see how customers are feeling based on text they use within the app.
This example uses simple
The IBM Watson Swift SDK is open source and available on Github, so feel free to view the documentation and source code, open issues, submit feature requests, or even make improvements of your own via pull requests!