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); }];}
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...
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With