TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2015 |
Maintained by Oliver Letterer.
Depends on: | |
AFNetworking | ~> 3.0 |
CloudBridge | ~> 1.4 |
CloudBridge helps synchronizing Your CoreData managed objects with various Cloud backends and ships with native support for RESTful JSON backends and CloudKit.
CloudBridge exposes the following convenience methods on NSManagedObject
:
+ (void)fetchObjectsMatchingPredicate:(NSPredicate *)predicate
withCompletionHandler:(void(^)(NSArray *fetchedObjects, NSError *error))completionHandler;
- (void)fetchObjectsForRelationship:(NSString *)relationship withCompletionHandler:(void(^)(NSArray *objects, NSError *error))completionHandler;
- (void)createWithCompletionHandler:(void(^)(id managedObject, NSError *error))completionHandler;
- (void)reloadWithCompletionHandler:(void(^)(id managedObject, NSError *error))completionHandler;
- (void)saveWithCompletionHandler:(void(^)(id managedObject, NSError *error))completionHandler;
- (void)deleteWithCompletionHandler:(void(^)(NSError *error))completionHandler;
which can be called from any NSManagedObjectContext
thread and are routed through the managed objects CBRCloudBridge
. The callbacks are always guaranteed to be delivered on the main thread.
To start using the convenience methods on NSManagedObject
, You need to configure a CBRCloudBridge
instance. A CBRCloudBridge
instance is responsible for bridging between a CoreDataStack and your backend.
Because setting up a correct and responsible CoreData stack can be challaging, CloudBridge
relies on SLCoreDataStack, which takes care of all the heavy lifting and edge cases for you. Implement your application specific CoreData stack as a subclass of SLCoreDataStack
:
@interface MyCoreDataStack : SLCoreDataStack
@end
@implementation MyCoreDataStack
- (NSString *)managedObjectModelName
{
return @"MyManagedObjectModel";
}
@end
The actual communication with each Cloud backend is encapsulated in an object conforming to the CBRCloudConnection
protocol
and is shipped in it's own CocoaPod dependency.
If you want to connect to a CloudKit backend, add pod 'CBRCloudKitConnection'
to Your Podfile.
If you want to connect to a RESTful JSON backend, add pod 'CBRRESTConnection'
to Your Podfile.
More information can be found in the CBRRESTConnection or CBRCloudKitConnection documentation.
As a last step, setup your CloudBridge stack as follows:
CKDatabase *database = [CKContainer defaultContainer].privateCloudDatabase;
MyCoreDataStack *stack = [MyCoreDataStack sharedInstance];
CBRCloudKitConnection *connection = [[CBRCloudKitConnection alloc] initWithDatabase:database];
CBRCloudBridge *cloudBridge = [[CBRCloudBridge alloc] initWithCloudConnection:connection coreDataStack:stack];
[NSManagedObject setCloudBridge:cloudBridge];
NSURL *serverURL = ...;
MyCoreDataStack *stack = [MyCoreDataStack sharedInstance];
id<CBRPropertyMapping> propertyMapping = [[CBRUnderscoredPropertyMapping alloc] init];
CBRRESTConnection *connection = [[CBRRESTConnection alloc] initWithBaseURL:serverURL propertyMapping:propertyMapping];
CBRCloudBridge *cloudBridge = [[CBRCloudBridge alloc] initWithCloudConnection:connection coreDataStack:stack];
[NSManagedObject setCloudBridge:cloudBridge];
Component | State | Version | License | Platform |
---|---|---|---|---|
CloudBridge | ||||
CBRRESTConnection | ||||
CBRCloudKitConnection | ||||
CBRManagedObjectCache | ||||
CBRManagedObjectFormViewController | ||||
CBRRelationshipResolver |
Oliver Letterer, [email protected]
CloudBridge is available under the MIT license. See the LICENSE file for more info.