⚠️不再维护⚠️

此库已停止使用,不再提供支持。

此仓库将不再更新。该仓库将保持只读模式。

请查看 fork 列表,了解持续开发的工作 #194

有关常见问题解答和其他信息,请参阅 Cloudant 博客

swift-cloudant

Version Platform Build Status

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

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

早期版本

这是该库的早期版本,支持以下操作

我们将在即将发布的版本中完善功能集。

目前,它不支持从 Objective-C 调用。

支持

SwiftCloudant 提供支持,但由于它是早期版本,因此仅在“尽力而为”的基础上提供支持。

平台

目前 Swift Cloudant 支持

Swift 版本

平台

Swift Cloudant 不支持

在您的项目中使用

SwiftCloudant 可以使用 Swift Package Manager 和 CocoaPods 获得。

要与 CocoaPods 一起使用,请将以下行添加到您的 Podfile 中

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

要与 swift package manager 一起使用,请将以下行添加到 Package.swift 中的 dependencies 中

.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