CBRRESTConnection 1.4.2

CBRRESTConnection 1.4.2

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.

Public API

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.

Quick start

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.

1. Implement Your CoreDataStack

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

2. Choose Your Cloud backend

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.

3. Setup Your CloudBridge

As a last step, setup your CloudBridge stack as follows:

CloudKit backend

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];

RESTful backend

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];

4. Enjoy

Installation

Components status

Component State Version License Platform
CloudBridge
CBRRESTConnection
CBRCloudKitConnection
CBRManagedObjectCache
CBRManagedObjectFormViewController
CBRRelationshipResolver

Author

Oliver Letterer, [email protected]

License

CloudBridge is available under the MIT license. See the LICENSE file for more info.