GithubHelp home page GithubHelp logo

mukang / swift-ipfs-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ipfs-shipyard/swift-ipfs-http-client

0.0 2.0 0.0 181 KB

A Swift client library for the IPFS API.

License: MIT License

Swift 99.55% Objective-C 0.45%

swift-ipfs-api's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.