![]() |
Couchbase Lite
Objective-C API for iOS and Mac OS
|
A configurable mapping from CBLDocument to CBLModel.
It associates a model class with a value of the document's "type" property.
Instance Methods | |
| (id) | - modelForDocument: |
| Given a document, attempts to return a CBLModel for it. More... | |
| (void) | - registerClass:forDocumentType: |
| Associates a value of the "type" property with a CBLModel subclass. More... | |
| (nullable Class) | - classForDocument: |
| Returns the appropriate CBLModel subclass for this document. More... | |
| (nullable Class) | - classForDocumentType: |
| Looks up the CBLModel subclass that's been registered for a document type. More... | |
| (nullable NSString *) | - documentTypeForClass: |
| Looks up the document type for which the given class has been registered. More... | |
| (CBLArrayOf(NSString *) | - documentTypesForClass: |
| Looks up the document types for which the given class has been registered. More... | |
Class Methods | |
| (instancetype) | + sharedInstance |
| Returns a global shared CBLModelFactory that's consulted by all databases. More... | |
| + (instancetype) sharedInstance |
Returns a global shared CBLModelFactory that's consulted by all databases.
Mappings registered in this instance will be used as a fallback by all other instances if they don't have their own.
| - (id) modelForDocument: | (CBLDocument *) | document |
Given a document, attempts to return a CBLModel for it.
If the document's modelObject property is set, it returns that value. If the document's "type" property has been registered, instantiates the associated class. Otherwise returns nil.
| - (void) registerClass: | (id) | classOrName | |
| forDocumentType: | (NSString *) | type | |
Associates a value of the "type" property with a CBLModel subclass.
When a document with this type value is loaded as a model, the given subclass will be instantiated (unless you explicitly instantiate a different CBLModel subclass.) As a bonus, when a model of this class is created with a new document, the document's "type" property will be set to the associated value.
| classOrName | Either a CBLModel subclass, or its class name as an NSString. |
| type | The value value of a document's "type" property that should indicate this class. |
| - (nullable Class) classForDocument: | (CBLDocument *) | document |
Returns the appropriate CBLModel subclass for this document.
The default implementation just passes the document's "type" property value to -classForDocumentType:, but subclasses could override this to use different properties (or even the document ID) to decide.
| - (nullable Class) classForDocumentType: | (NSString *) | type |
Looks up the CBLModel subclass that's been registered for a document type.
| - (nullable NSString*) documentTypeForClass: | (Class) | modelClass |
Looks up the document type for which the given class has been registered.
If it's unregistered, or registered with multiple types, returns nil.
| - (CBLArrayOf(NSString*) documentTypesForClass: | (Class) | modelClass |
Looks up the document types for which the given class has been registered.