Latest 0.1.1
Homepage https://github.com/haijianhuo/HHBackand-iOS-SDK
License MIT
Platforms ios 8.0
Dependencies Alamofire, SwiftKeychainWrapper
Frameworks Foundation
Authors

Backand SDK for iOS.

About

HHBackand-iOS-SDK is written in Swift 3 and provides most of the functionality that the Backand REST API offers.

Contents

Requirements

  • iOS 8.0+
  • Xcode 8.2

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate HHBackand-iOS-SDK into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'HHBackand-iOS-SDK'

Then, run the following command:

$ pod install

Manually

Add Backand.swift to your project in Xcode.

Basic Usage

Setup

Import Backand into your AppDelegate.swift:

import Backand

Setup the SDK in application:didFinishLaunchingWithOptions:

Backand.sharedInstance.setAppName("app-name")
Backand.sharedInstance.setAnonymousToken("anonymous-token")
Backand.sharedInstance.setSignUpToken("sign-up-token")

Get Item(s)

To retrieve a single item:

let backand = Backand.sharedInstance
backand.getItemWithId("id", "ObjectName", options: nil) { result in
    switch result {
    case .success(let item):
        print(item)
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

To retrieve multiple items:

let backand = Backand.sharedInstance
backand.getItemsWithName("ObjectName", options: nil) { result in
    switch result {
    case .success(let item):
        print(item)
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

Create item

let backand = Backand.sharedInstance
backand.createItem(["name": "Jake", "message": "Hello world!", "score": 36], name: "MessageOfTheDay", options: nil) { result in
    switch result {
    case .success:
        // Yay.
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

Update item

let backand = Backand.sharedInstance
backand.updateItemWithId("47", item: ["message": "Hello everyone."], name: "MessageOfTheDay", options: nil) { result in
    switch result {
    case .success:
        // Yay.
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

Delete item

let backand = Backand.sharedInstance
backand.deleteItemWithId("47", name: "MessageOfTheDay") { result in
    switch result {
    case .success:
        // Yay.
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

User sign up

let backand = Backand.sharedInstance
let user = [
    "firstname": "First name",
    "lastname": "Last name"
    "email": "[email protected]"
    "password": "password"
    "confirmPassword": "password again"
]
backand.signUp(user) { result in
    switch result {
    case .success:
        // Yay.
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

User sign in

let backand = Backand.sharedInstance
backand.signIn("[email protected]", password: "password") { result in
    switch result {
    case .success:
        // Yay.
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

Advanced usage

Run a custom defined query

Backand allows you to define queries in the cloud. Here’s how you can run them:

let backand = Backand.sharedInstance
backand.runQueryWithName("query-name", parameters: nil) { result in
    switch result {
    case .success(let item):
        print(item)
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

Bulk actions

Bulk actions allow you to perform more than one operation in a single request.

let backand = Backand.sharedInstance
let baseURL = backand.getApiUrl()
let createAction = Action(method: .POST, url: baseURL+"/1/ObjectNameHere", data: ["name": "Jake", "message": "Hi!"])]
let updateAction = Action(method: .PUT, url: baseURL+"/1/ObjectNameHere/ID", data: ["name": "Alex", "message": "Hello!"])
let deleteAction = Action(method: .DELETE, url: baseURL+"/1/ObjectNameHere/ID", data: nil)
let actions = [createAction, updateAction, deleteAction]

backand.performActions(actions) { result in
    switch result {
    case .success:
        // Yay.
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

Options & filters

let backand = Backand.sharedInstance

// More operator types available 
let filterName = Filter(fieldName: "name", operatorType: .Equal, value: "Jake")
let filterMessage = Filter(fieldName: "message", operatorType: .StartsWith, value: "Hello")

// More options available
let options: [BackandOption] = [
    .PageSize(10),
    .PageNumber(7),
    .FilterArray([filterName, filterMessage]),
    .ExcludeArray([.Metadata, .TotalRows])
]

// Example request
backand.getItemsWithName("ObjectName", options: options) { result in
    switch result {
    case .success(let items):
        print(items)
    case .failure(let error):
        // Ouch. Should probably do something here.
    }
}

Latest podspec

{
    "name": "HHBackand-iOS-SDK",
    "module_name": "Backand",
    "version": "0.1.1",
    "summary": "A Backand SDK for iOS.",
    "description": "A simple SDK for interacting with the Backand REST API for iOS, written in Swift.",
    "homepage": "https://github.com/haijianhuo/HHBackand-iOS-SDK",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Haijian Huo": "[email protected]"
    },
    "source": {
        "git": "https://github.com/haijianhuo/HHBackand-iOS-SDK.git",
        "tag": "0.1.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Source/**",
    "frameworks": "Foundation",
    "dependencies": {
        "Alamofire": [
            "~> 4.4.0"
        ],
        "SwiftKeychainWrapper": [
            "~> 3.0.1"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This