Inherits from NSObject
Conforms to NMBSerializer
Declared in NMBase.h

Overview

NMBase is the root for all. It should be a singleton in project or bound with NSPersistentStoreCoordinator.

Properties

defaultServer

The only initialized server of the reciever.

@property (nonatomic, readonly, weak) NMBServer *defaultServer

Discussion

This property is only available when the NCfgK_AllowMutipleServers set to NO in the configs passed into the init method, otherwise it returns nil.

Declared In

NMBase.h

modelMapper

The instance that is responsible for mapping entities and properties among different versions of NSManagedObjectModel.

@property (nonatomic, readonly, weak) id<NMBModelMapper> modelMapper

Discussion

If a model mapper is needed by the reciever, refer it by the key NCfgK_ModelMapper in the configs passed into the init method.

Declared In

NMBase.h

serializer

The instance that is responsible for serializing some objects that can’t be translated to JSON directly.

@property (nonatomic, weak) id<NMBSerializer> serializer

Discussion

If you don’t implement a serializer yourself, there is already one which only capable to serialize several common class instance, like NSDate.

Declared In

NMBase.h

servers

The servers decribed in configs will be instantiated and can be access via this property.

@property (nonatomic, readonly) NSArray *servers

Declared In

NMBase.h

userMOContext

The NSManagedObjectContext used by NMBase to access your data.

@property (nonatomic, readonly) NSManagedObjectContext *userMOContext

Discussion

You are supposed not to use this context to CRUD your data, because it’s created and runs on a private thread of NMBase. But you should add observer on NSNotificationCenter with event name NSManagedObjectContextDidSaveNotification. So that you can merge any changes NMBase fetching from cloud.

Declared In

NMBase.h

userPSCoordinator

The NSPersistentStoreCoordinator to which the reciever is bound to.

@property (nonatomic, readonly, weak) NSPersistentStoreCoordinator *userPSCoordinator

Declared In

NMBase.h

Instance Methods

application:openURL:sourceApplication:annotation:

Handle the “openURL” event in AppDelegate. Put it in the method with same name in your AppDelegate.

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

Parameters

application

Pass the same parameter.

url

Pass the same parameter.

sourceApplication

Pass the same parameter.

annotation

Pass the same parameter.

Return Value

Indicates if NimbusBase can handle this url.

Declared In

NMBase.h

importDataFromMainMOContext

Import and stage the data from your data base.

- (NMBPromise *)importDataFromMainMOContext

Return Value

This operation will scan your whole data base, it may cost a long time, so it is designed to be async. You will be notified by the callbacks of NMBPromise if the import succeeds or fials.

Discussion

This method is useful when the first time you track your changes with NMBase but there are already some stored application data. Or you want to stage the missed changes, while there is a cessation of tracking.

Declared In

NMBase.h

initWithPSCoordinator:configs:

The only init method shoud be used on NMBase.

- (id)initWithPSCoordinator:(NSPersistentStoreCoordinator *)psc configs:(NSDictionary *)cfgs

Parameters

psc

The NSPersistentStoreCoordinator your NSManagedObjectContext is base on.

cfgs

An instance of NSDictionary contains the information of NMBase and all its servers.

Return Value

An instance of NMBase.

Discussion

This instance contains information of your model and the stored data of your application, base on which NMBase will access your data and transfer them to the cloud.

Declared In

NMBase.h

saveMOContext

Save all of unsaved changes NMBase make.

- (void)saveMOContext

Discussion

This method is supposed to be called when application is going to background or be terminated.

Declared In

NMBase.h

trackChangesOfMOContext:

Track the changes of the user’s NSManagedObjectContext.

- (void)trackChangesOfMOContext:(NSManagedObjectContext *)moc

Parameters

moc

The NSManagedObjectContext you want to be tracked.

Discussion

Only the changes of tracked context can be staged by NMBase, and transfered to cloud during a synchronization. So track every context you would write on with this method.

Declared In

NMBase.h

untrackChangesOfMOContext:

Stop tracking changes of user’s NSManagedObjectContext.

- (void)untrackChangesOfMOContext:(NSManagedObjectContext *)moc

Parameters

moc

The NSManagedObjectContext you don’t want to track anymore.

Declared In

NMBase.h