SwiftCloudant 0.9.0

SwiftCloudant 0.9.0

测试已测试
语言语言 SwiftSwift
许可证 Apache-2.0
发布日期最后一次发布2019年4月
SPM支持 SPM

Rhys ShortSam SmithEsteban Laver 维护。



  • IBM Cloudant

swift-cloudant

Version Platform Build Status

应用程序使用 swift-cloudant 在 Cloudant 或 CouchDB 上存储、索引和查询远程 JSON 数据。

Swift-Cloudant 是一个用 Swift 编写的 Apache CouchDB™ 客户端。它由 Cloudant 构建,并可在 Apache 2.0 许可证 下提供。

早期发布

这是一个早期发布的库版本,支持以下操作

  • 根据文档 ID 获取文档。
  • 更新和删除文档。
  • 创建和删除数据库。
  • 变化流操作
  • 创建、更新和删除附件。
  • 查询视图。
  • 创建、删除和查询索引。

我们将在未来的版本中完善功能集。

当前不支持从 Objective-C 中调用。

支持

SwiftCloudant 受支持,但由于它是早期发布版本,因此在“尽最大努力”的基础上提供支持。

平台

目前Swift Cloudant支持

Swift版本

  • 最低Swift语言版本4.2
  • 最低Swift工具版本5.0

平台

  • macOS
  • Linux

Swift Cloudant在以下平台上不受支持

  • iOS(应能工作,但尚未测试)
  • tvOS
  • watchOS

在你的项目中使用

SwiftCloudant可以通过Swift包管理器和CocoaPods使用。

使用CocoaPods,请在Podfile中添加以下行

pod 'SwiftCloudant', :git => 'https://github.com/cloudant/swift-cloudant.git'

使用Swift包管理器,请在Package.swift的依赖项中添加以下行

.Package(url: "https://github.com/cloudant/swift-cloudant.git")

库概述

import SwiftCloudant

// Create a CouchDBClient
let cloudantURL = URL(string:"https://username.cloudant.com")!
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)")
        default:
            print("Encountered an error while creating a document. Error:\(error)")
        }
    } else {
        print("Created document \(response?["id"]) with revision id \(response?["rev"])")
    }
}
client.add(operation:create)

// create an attachment
let attachment = "This is my awesome essay attachment for my document"
let putAttachment = PutAttachmentOperation(name: "myAwesomeAttachment",
    contentType: "text/plain",
    data: attachment.data(using: 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)")
    }   
}
client.add(operation:read)

// 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")
    }   
}
client.add(operation:delete)

需求

目前没有第三方依赖。

贡献者

CONTRIBUTORS

为项目贡献力量

CONTRIBUTING

许可

查看 LICENSE