This project has been deprecated and is no longer actively maintained. Proceed at your own risk!
Bluemix Client SDK for Object Storage in Swift
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.
- iOS 8.0+
- Xcode 8+
- Swift 3.0
The Bluemix Mobile Services Swift SDKs are available via Cocoapods and Carthage.
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
.
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.
- Importing module
- Connecting to Object Storage
- Managing containers
- Managing objects
- Account metadata
- Types of errors
View the complete API reference here.
--
import BluemixObjectStorage
--
Use ObjectStorage
instance to connect to IBM Object Storage service.
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")
}
}
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")
}
}
--
Use ObjectStorage instance to manage containers.
objstorage.create(container: "container-name") { (error, container) in
if let error = error {
print("create container error :: \(error)")
} else {
print("create container success :: \(container?.name)")
}
}
objstorage.retrieve(container: "container-name") { (error, container) in
if let error = error {
print("retrieve container error :: \(error)")
} else {
print("retrieve container success :: \(container?.name)")
}
}
objstorage.retrieveContainersList { (error, containers) in
if let error = error {
print("retrieve containers list error :: \(error)")
} else {
print("retrieve containers list success :: \(containers?.description)")
}
}
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
container.delete { (error) in
if let error = error {
print("delete container error :: \(error)")
} else {
print("delete container success")
}
}
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")
}
}
container.retrieveMetadata { (error, metadata) in
if let error = error {
print("retrieveMetadata error :: \(error)")
} else {
print("retrieveMetadata success :: \(metadata)")
}
}
--
Use ObjectStorageContainer
instance to manage objects inside of particular container
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)")
}
}
container.retrieve(object: "object-name") { (error, object) in
if let error = error {
print("retrieve object error :: \(error)")
} else {
print("retrieve object success :: \(object?.name)")
}
}
container.retrieveObjectsList { (error, objects) in
if let error = error {
print("retrieveObjectsList error :: \(error)")
} else {
print("retrieveObjectsList success :: \(objects?.description)")
}
}
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
object.load(shouldCache: false) { (error, data) in
if let error = error {
print("load error :: \(error)")
} else {
print("load success :: \(data)")
}
}
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")
}
}
object.retrieveMetadata { (error, metadata) in
if let error = error {
print("retrieve metadata error :: \(error)")
} else {
print("retrieve metadata success :: \(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")
}
}
objstorage.retrieveMetadata { (error, metadata) in
if let error = error {
print("retrieve metadata error :: \(error)")
} else {
print("retrieve metadata success :: \(metadata)")
}
}
--
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
}
--
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.