ipfs-shipyard / swift-ipfs-http-client

A Swift client library for the IPFS HTTP API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

swift-ipfs-api

standard-readme compliant

A Swift client library for the IPFS API.

For more information about IPFS or the API commands click the links.

The Swift IPFS API shell/client is an asynchronous library that provides native calls to an IPFS node.

Table of Contents

Install

In the root of your project:

  • Add a Cartfile (or use an existing one) with the following:
github "ipfs/swift-ipfs-api" "master"
  • To fetch and build the dependencies, type:

carthage update --platform Mac

or

carthage update --platform iOS

or

carthage update

if you want both platforms.

For more information on how to install via Carthage see the README

Usage

Add the required frameworks to your project in Xcode:

  • In your target's build phases tab.

  • Click the + in the upper left corner and pick the New Copy Files Phase from the drop-down.

  • Select the Destination Frameworks and click the + to Add Other... buttons.

  • Navigate to the Carthage/Build/Mac directory in your project root and select all the frameworks in the folder.

Examples

In your code:

import SwiftIpfsApi

do {
  let api = try IpfsApi(host: "127.0.0.1", port: 5001)

  try api.id() { (idData : JsonType) in
    guard let id = idData.object?["ID"]?.string else {
      return
    }
    print("Yay, I've got an id: \(id)")
  }
} catch {
  print(error.localizedDescription)
}

The Swift IPFS API client is asynchronous, but if you want to use a command synchronously (eg. if you run it in its own thread) you can always use dispatch groups:

let group = dispatch_group_create()
dispatch_group_enter(group)

let multihash = try! fromB58String("QmXsnbVWHNnLk3QGfzGCMy1J9GReWN7crPvY1DKmFdyypK") 

try! api.refs(multihash, recursive: false) {
    result in
    for mh in result {
        print(b58String(mh))
    }
    
    dispatch_group_leave(group)
}

dispatch_group_wait(group, DISPATCH_TIME_FOREVER)

Requirements

Swift 3

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT

About

A Swift client library for the IPFS HTTP API.

License:MIT License


Languages

Language:Swift 99.6%Language:Objective-C 0.4%