Home

Awesome

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:

github "ipfs/swift-ipfs-api" "master"

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:

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