Latest 0.1.0
Homepage https://github.com/jakelawson1/Backand-iOS-SDK
License MIT
Platforms ios 8.0
Dependencies Alamofire, SwiftKeychainWrapper
Frameworks Foundation
Authors

Backand SDK for iOS.

About

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

Things to do:

  • Social login (GitHub, Twitter, Facebook & Google)
  • Token refresh
  • Get information on currently logged in user
  • Realtime using SocketIO
  • Improve error handling with custom error types?
  • Tests

Should I use this in a live app?

Probably not (yet). If you don’t require any user management and are just using anonymous access to Backand, then sure (token refresh is pretty important). This SDK is in very early development. It should progress rapidly overtime with any luck.

Contents

Requirements

  • iOS 8.0+
  • Xcode 7.3

Installation

CocoaPods

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

$ gem install cocoapods

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

pod 'Backand-iOS-SDK', '~> 0.1.0'

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": "Backand-iOS-SDK",
    "module_name": "Backand",
    "version": "0.1.0",
    "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/jakelawson1/Backand-iOS-SDK",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Jake Lawson": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jakelawson1/Backand-iOS-SDK.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Source/**",
    "frameworks": "Foundation",
    "dependencies": {
        "Alamofire": [
            "~> 3.4"
        ],
        "SwiftKeychainWrapper": []
    }
}

Pin It on Pinterest

Share This