Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

RxSwift Extension

johnnycoinbase edited this page Jan 10, 2019 · 1 revision

CoinbaseSDK provides an extension to use it with RxSwift.

Adding Rx extension for CoinbaseSDK

CocoaPods

If you use CocoaPods, add 'CoinbaseSDK/RxSwift' pod into your Podfile:

pod 'CoinbaseSDK', '~> 1.0'
pod 'CoinbaseSDK/RxSwift', '~> 1.0'

In the source file where you want to use CoinbaseSDK with Rx wrappers add:

import CoinbaseSDK

Carthage

If you use Carthage, add "coinbase/coinbase-ios-sdk" dependency reference into your Cartfile:

github "coinbase/coinbase-ios-sdk"

Run carthage update to build the framework and drag the built CoinbaseSDK.framework and RxCoinbaseSDK.framework into your Xcode project.

In the source file where you want to use RxSwift wrappers add:

import CoinbaseSDK
import RxCoinbaseSDK

Swift Package Manager

Once you have your Swift package set up, add "https://github.com/coinbase/coinbase-ios-sdk" dependency reference in dependencies value of your Package.swift:

dependencies: [
        .package(url: "https://github.com/coinbase/coinbase-ios-sdk")
    ]

Also in Package.swift add "RxCoinbaseSDK" to the dependencies of the specific target where you want to use RxSwift wrappers:

targets: [
    .target(
        name: "project_name",
        dependencies: ["CoinbaseSDK", "RxCoinbaseSDK"]),
]

In the source file where you want to use RxSwift wrappers add:

import CoinbaseSDK
import RxCoinbaseSDK

Important

Swift Package Manager currently does not support resources. CoinbaseSDK requires additional resource files to work properly (Trusted SSL Certificates). If you want to use Swift Package Manager you should provide those resources manually.

You can find the required resources in Coinbase iOS SDK GitHub repository under Source/Supporting Files/PinnedCertificates path. Collect those files and add them to your project.

  • Using Xcode:

    You should additionally configure CoinbaseSDK target. In tab Build Phases add new phase by selecting New Copy File Phase. Drag and Drop required resources to this phase.

  • Using console:

    To provide the required resources you should copy them to a location with built files.

    Example: If required files are located in directory Resources and you building for x86_64-apple-macosx10.10 platform in debug mode then resources can be copied with the command:

    cp Resources/* ./.build/x86_64-apple-macosx10.10/debug

Using Rx extension

Rx extension for CoinbaseSDK provides methods to make API calls wrapped in Single<Element>.

All available Rx methods have rx_ prefix naming pattern.

E.g. for transactionResource.list() method Rx wrapper would be transactionResource.rx_list():

coinbase.transactionResource
    .rx_list(accountID: <account_id>,
             expandOptions: [.from, .to]))
    .subscribe(onSuccess: { transactions in ... },
               onError: { error in ...})
    .disposed(by: disposeBag)