Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ensembles in iOS swift

I would like to use Drew McCormack's Ensembles from github to relieve my current iOS/swift/coredata/iCloud induced headache. All of the Ensembles examples are in Objective-C. I have it as a Framework in my project, but being a weekend coder, I can't extrapolate how to use it from the ObjC example code.

Has anyone seen a How-To for Ensembles using swift?

Adding: I have it as a framework, but how do I set it up and have it start Leeching? The Obj-C way is to

//SetupEnsemble
cloudFileSystem=[[CDEICloudFileSystemalloc] initWithUbiquityContainerIdentifier:@"container"];
ensemble=[[CDEPersistentStoreEnsemblealloc]initWithEnsembleIdentifier:@"MainStore" persistentStoreURL:storeURL
        managedObjectModelURL:modelURL
cloudFileSystem:cloudFileSystem]; ensemble.delegate=self;

and then Leech

if(!ensemble.isLeeched){
[ensemble leechPersistentStoreWithCompletion:^(NSError *error) {
if (error) NSLog(@"Could not leech to ensemble: %@", error); }];}
like image 899
Mark Avatar asked Nov 01 '22 02:11

Mark


1 Answers

The following steps describe how you add ensembles with the iCloud + Dropbox filesystem to your project:

Add a 'Podfile' to your project with this contents:

target :YOUR_TARGET_NAME do
platform :ios, '7.0'
pod "Ensembles", :git => 'https://github.com/drewmccormack/ensembles.git'
pod "Ensembles/Dropbox", :git => 'https://github.com/drewmccormack/ensembles.git'
link_with 'YOUR_TARGET_NAME'
end

Run 'pod install' from your terminal

Create a ObjC bridging header

Add Ensembles (and other frameworks to the bridging header):

#import <Foundation/Foundation.h>
#import <Ensembles/Ensembles.h>
#import "DropboxSDK.h"
#import "CDEDropboxCloudFileSystem.h"

Happy coding:

var ensemble:CDEPersistentStoreEnsemble?
var ensembleFileSystem:CDECloudFileSystem?

ensembleFileSystem = CDEICloudFileSystem(
  ubiquityContainerIdentifier: "SOME_CONTAINER",
  relativePathToRootInContainer: "STORE_ROOT_PATH"
)

ensemble = CDEPersistentStoreEnsemble(
  ensembleIdentifier: "IDENTIFIER",
  persistentStoreURL: "STORE_URL",
  persistentStoreOptions:nil,
  managedObjectModelURL:"MOM_URL",
  cloudFileSystem:ensembleFileSystem,
  localDataRootDirectoryURL:"DATA_ROOT_URL"
)

e.leechPersistentStoreWithCompletion({ (error:NSError?) -> Void in
  // check for error, etc...
})
like image 184
lars Avatar answered Nov 15 '22 06:11

lars