CloudMine.Logo.HiRes.type_1.png
Ë
Blog Home
By 0to5 • July 30, 2014

CloudMine: Now With Swift

The recent unveiling of iOS 8 introduced a new programming language: Swift.

Many are wondering when their favorite services will support this innovative new language. For CloudMine, that time is now. With the new CloudMine Swift library, it's easier than ever before to upload, download, and manage your data and access other CloudMine functionality.

To use our library in your Swift projects, import the header file into your project's bridge header.

#import <CloudMine/CloudMine.h>
view rawimport.m hosted with ❤ by GitHub

You can download our library here, or install it using CocoaPods. A bridge header is a file that allows a developer to use Objective-C libraries in her Swift code. Be sure to designate this header in the Swift Compiler section of project's target. For a more complete discussion, see this StackOverflow answer.

Both Swift and CloudMine are based upon the principles of speed and simplicity. Here are some quick examples to get you up and running with CloudMine:

First, create a CloudMine object to facilitate the transfer of data:

var myObject = CMObject(objectId: "mycar")
view rawobject.swift hosted with ❤ by GitHub

This can be created wherever the object is needed.

In the past with Objective-C, this is how you would save an object:

[mycar save:^(CMObjectUploadResponse *response) {
NSLog(@"Status: %@", [response.uploadStatuses objectForKey:mycar.objectId]);
}];
view rawsave.m hosted with ❤ by GitHub

To save an object with Swift you simply call the save method on your object:

myObject.save {
(response : CMObjectUploadResponse!) -> Void in
NSLog("Object was uploaded successfully! %@", response.uploadStatuses)
}
view rawsave.swift hosted with ❤ by GitHub

Here's a shorter version:

myObject.save {
response in NSLog("Object was uploaded successfully! %@", response.uploadStatuses)
}
view rawshorterSave.swift hosted with ❤ by GitHub

Object retrieval in Objective-C:

CMStore *store = [CMStore defaultStore];
[store allObjectsWithOptions:nil
callback:^(CMObjectFetchResponse *response) {
NSLog(@"Objects: %@", response.objects);
}
];
view rawretrieval.m hosted with ❤ by GitHub

The same in Swift:

CMStore.defaultStore().allObjectsWithOptions(nil, callback: {
response : CMObjectFetchResponse!) -> Void in
NSLog("Fetched: %@", response.objects);
})
view rawretrieval.swift hosted with ❤ by GitHub

It's as simple as that. In less than 10 lines of code you're on your way to building better apps, more easily, with CloudMine. Send us an email at support@cloudmine.me if you have any questions at all. We are always here to help.


Source: Hubspot Feed