Latest 1.0.2
Homepage https://github.com/ibm-bluemix-mobile-services/bluemix-objectstorage-clientsdk-swift
License Apache License, Version 2.0
Platforms ios 8.0, requires ARC
Dependencies BMSCore
Authors

[BluemixObjectStorageSDK]

Object Storage

Bluemix Client SDK for Object Storage in Swift

BluemixObjectStorage
Build Status
Platform
Codacy Badge
Coverage Status

Table of Contents

Summary

Object Storage provides an unstructured cloud data store to build and deliver cloud applications and services with lowered cost, reliability, and speed to market. Bluemix developers and users can access and store unstructured data content and can interactively compose and connect to applications and services. The Object Storage service also provides programmatic access via API, SDKs and a consumable UI for object management.

You can use this client SDK to store and retrieve binary data on your Object Storage service instance on Bluemix from your iOS application.

Read the official documentation for information about getting started with Object Storage.

Requirements

  • iOS 8.0+
  • Xcode 8+
  • Swift 3.0

Installation

The Bluemix Mobile Services Swift SDKs are available via Cocoapods and Carthage.

Cocoapods

To install BluemixObjectStorage using Cocoapods, add it to your Podfile:

use_frameworks!

target 'MyApp' do
    pod 'BluemixObjectStorage'
end

Make sure you have Cocoapods version 1.1.0.rc.2 (or later) installed. Then run the pod install command. To update to a newer release of BluemixObjectStorage, use pod update BluemixObjectStorage.

Carthage

To install BMSAnalytics with Carthage, follow the instructions here.

Add this line to your Cartfile:

github "ibm-bluemix-mobile-services/bluemix-objectstorage-clientdsk-swift"

Then run the carthage update command. Once the build is finished, add BluemixObjectStorage.framework, BMSCore.framework and BMSAnalyticsAPI.framework to your project.

Example Usage

View the complete API reference here.

Importing module

Adding the framework
import BluemixObjectStorage

View examples

Connecting to Object Storage

Use ObjectStorage instance to connect to IBM Object Storage service.

Connect to the IBM Object Storage service using userId and password
let objstorage = ObjectStorage(projectId: "your-project-id")
objstorage.connect(userId: "your-service-userId",
                   password: "your-service-password",
                   region: ObjectStorage.Region.Dallas) { (error) in
    if let error = error {
        print("connect error :: (error)")
    } else {
        print("connect success")
    }                           
}
Connect to the IBM Object Storage service using explicit authToken
let objstorage = ObjectStorage(projectId: "your-project-id")
objstorage.connect(authToken: "your-auth-token",
                   region: ObjectStorage.Region.Dallas) { (error) in
    if let error = error {
        print("connect error :: (error)")
    } else {
        print("connect success")
    }                           
}

View examples

Managing containers

Use ObjectStorage instance to manage containers.

Create a new container
objstorage.create(container: "container-name") { (error, container) in
    if let error = error {
        print("create container error :: (error)")
    } else {
        print("create container success :: (container?.name)")
    }
}
Retrieve an existing container
objstorage.retrieve(container: "container-name") { (error, container) in
    if let error = error {
        print("retrieve container error :: (error)")
    } else {
        print("retrieve container success :: (container?.name)")
    }
}
Retrieve a list of existing containers
objstorage.retrieveContainersList { (error, containers) in
    if let error = error {
        print("retrieve containers list error :: (error)")
    } else {
        print("retrieve containers list success :: (containers?.description)")
    }
}
Delete an existing container
objstorage.delete(container: "container-name") { (error) in
    if let error = error {
        print("delete container error :: (error)")
    } else {
        print("delete container success")
    }
}

You can also use ObjectStorageContainer instance to manage containers

Delete the container
container.delete { (error) in
    if let error = error {
        print("delete container error :: (error)")
    } else {
        print("delete container success")
    }
}
Update container metadata
let metadata = ["X-Container-Meta-SomeName": "SomeValue"]
container.update(metadata: metadata) { (error) in
    if let error = error {
        print("update metadata error :: (error)")
    } else {
        print("update metadata success")
    }
}
Retrieve container metadata
container.retrieveMetadata { (error, metadata) in
    if let error = error {
        print("retrieveMetadata error :: (error)")
    } else {
        print("retrieveMetadata success :: (metadata)")
    }
}

View examples

Managing Objects

Use ObjectStorageContainer instance to manage objects inside of particular container

Create a new object or update an existing one
let data = "testdata".data(using: .utf8)!
container.store(object: "object-name", data: data) { (error, object) in
    if let error = error {
        print("store object error :: (error)")
    } else {
        print("store object success :: (object?.name)")
    }
}
Retrieve an existing object
container.retrieve(object: "object-name") { (error, object) in
    if let error = error {
        print("retrieve object error :: (error)")
    } else {
        print("retrieve object success :: (object?.name)")
    }
}
Retrieve a list of existing objects
container.retrieveObjectsList { (error, objects) in
    if let error = error {
        print("retrieveObjectsList error :: (error)")
    } else {
        print("retrieveObjectsList success :: (objects?.description)")
    }
}
Delete an existing object
container.delete(object: "object-name") { (error) in
    if let error = error {
        print("delete object error :: (error)")
    } else {
        print("delete object success")
    }
}

Use ObjectStorageObject instance to load object content on demand

Load the object content
object.load(shouldCache: false) { (error, data) in
    if let error = error {
        print("load error :: (error)")
    } else {
        print("load success :: (data)")
    }
}
Update object metadata
let metadata = ["X-Object-Meta-SomeName": "SomeValue"]
object.update(metadata: metadata) { (error) in
    if let error = error {
        print("update metadata error :: (error)")
    } else {
        print("update metadata success")
    }
}
Retrieve object metadata
object.retrieveMetadata { (error, metadata) in
    if let error = error {
        print("retrieve metadata error :: (error)")
    } else {
        print("retrieve metadata success :: (metadata)")
    }
}

View examples

Account metadata

Update account metadata
let metadata = ["X-Account-Meta-SomeName": "SomeValue"]
objstorage.update(metadata: metadata) { (error) in
    if let error = error {
        print("update metadata error :: (error)")
    } else {
        print("update metadata success")
    }
}
Retrieve account metadata
objstorage.retrieveMetadata { (error, metadata) in
    if let error = error {
        print("retrieve metadata error :: (error)")
    } else {
        print("retrieve metadata success :: (metadata)")
    }
}

View examples

Types of errors

ObjectStorageError

The ObjectStorageError is an enum with possible failure reasons

enum ObjectStorageError: ErrorType {
    case connectionFailure
    case notFound
    case unauthorized
    case serverError
    case invalidUri
    case failedToRetrieveAuthToken
    case notConnected
    case cannotRefreshAuthToken
}

View examples

License

This package contains code licensed under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 and may also view the License in the LICENSE file within this package.

Latest podspec

{
    "name": "BluemixObjectStorage",
    "version": "1.0.2",
    "summary": "Bluemix Object Storage SDK",
    "homepage": "https://github.com/ibm-bluemix-mobile-services/bluemix-objectstorage-clientsdk-swift",
    "license": "Apache License, Version 2.0",
    "authors": {
        "IBM Bluemix Services Mobile SDK": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ibm-bluemix-mobile-services/bluemix-objectstorage-clientsdk-swift.git",
        "tag": "1.0.2"
    },
    "source_files": "BluemixObjectStorage/**/*",
    "exclude_files": "BluemixObjectStorage/**/*.plist",
    "dependencies": {
        "BMSCore": [
            "~> 2.0"
        ]
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This