Latest 0.9.0
License Apache License, Version 2.0
Platforms ios 8.0, osx 10.10


Build Status

Applications use swift-cloudant to store, index and query remote
JSON data on Cloudant or CouchDB.

Swift-Cloudant is an Apache CouchDB™ client written in Swift. It
is built by Cloudant and is available under the
Apache 2.0 license.


This is an early-release version of the library, with support for the following operations:

  • Getting documents by doc ID.
  • Updating and deleting documents.
  • Creating and deleting databases.
  • Changes Feed operations
  • Creating, updating and deleting of attachments.
  • Querying views.
  • Creating, deleting and querying indexes.

We will be rounding out the feature set in upcoming releases.

Currently it does not support being called from Objective-C.


SwiftCloudant is supported, however since it is an early release it is
on a "best effort" basis.


Currently Swift Cloudant supports:

Swift versions

  • Minimum Swift language version 4.2
  • Minimum Swift tools version 5.0


  • macOS
  • Linux

Swift Cloudant is unsupported on:

  • iOS (should work, but hasn’t been tested)
  • tvOS
  • watchOS

Using in your project

SwiftCloudant is available using the Swift Package Manager and CocoaPods.

To use with CocoaPods add the following line to your Podfile:

pod 'SwiftCloudant', :git => ''

To use with the swift package manager add the following line to your dependencies
in your Package.swift:

.Package(url: "")

Overview of the library

import SwiftCloudant

// Create a CouchDBClient
let cloudantURL = URL(string:"")!
let client = CouchDBClient(url:cloudantURL, username:"username", password:"password")
let dbName = "database"

// Create a document
let create = PutDocumentOperation(id: "doc1", body: ["hello":"world"], databaseName: dbName) {(response, httpInfo, error) in
    if let error = error as? SwiftCloudant.Operation.Error {
        switch error {
        case .http(let httpError):
            print("http error status code: (httpError.statusCode)  response: (httpError.response)")
            print("Encountered an error while creating a document. Error:(error)")
    } else {
        print("Created document (response?["id"]) with revision id (response?["rev"])")

// create an attachment
let attachment = "This is my awesome essay attachment for my document"
let putAttachment = PutAttachmentOperation(name: "myAwesomeAttachment",
    contentType: "text/plain",
    data: String.Encoding.utf8, allowLossyConversion: false)!,
    documentID: "doc1",
    revision: "1-revisionidhere",
    databaseName: dbName) { (response, info, error) in
        if let error = error {
            print("Encountered an error while creating an attachment. Error:(error)")
        } else {
            print("Created attachment (response?["id"]) with revision id (response?["rev"])")
client.add(operation: putAttachment)

// Read a document
let read = GetDocumentOperation(id: "doc1", databaseName: dbName) { (response, httpInfo, error) in
    if let error = error {
        print("Encountered an error while reading a document. Error:(error)")
    } else {
        print("Read document: (response)")

// Delete a document
let delete = DeleteDocumentOperation(id: "doc1",
    revision: "1-revisionidhere",
    databaseName: dbName) { (response, httpInfo, error) in
    if let error = error {
        print("Encountered an error while deleting a document. Error: (error)")
    } else {
        print("Document deleted")


Currently they are no third party dependencies.



Contributing to the project




Latest podspec

    "name": "SwiftCloudant",
    "version": "0.9.0",
    "summary": "SwiftCloudant is a client library for  Apache CouchDB / IBM Cloudant",
    "description": "SwiftCloudant is a client library for interacting withnApache CouchDB / IBM Cloudant.nnIt provides an operation based API for performing actionsnwith the Apache CouchDB HTTP API.",
    "homepage": "",
    "license": {
        "type": "Apache License, Version 2.0",
        "file": "LICENSE"
    "authors": {
        "IBM Cloudant": "[email protected]"
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    "source": {
        "git": "",
        "tag": "0.9.0"
    "source_files": [
    "swift_version": "4.2"

Pin It on Pinterest

Share This