Backand SDK for iOS.
Backand-iOS-SDK is written in Swift and provides most of the functionality that the Backand REST API offers.
- 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
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.
- iOS 8.0+
- Xcode 7.3
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
Add Backand.swift to your project in Xcode.
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")
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.
}
}
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.
}
}
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.
}
}
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.
}
}
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.
}
}
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.
}
}
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 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.
}
}
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.
}
}