CBLDocument

@interface CBLDocument : CBLProperties

A Couchbase Lite document. A document has key/value properties like an NSDictionary; their API is defined by the protocol CBLProperties. To learn how to work with properties, see that protocol’s documentation.

  • Undocumented

    Declaration

    Objective-C

    @interface CBLDocument : CBLProperties
  • The document’s ID.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull documentID;

    Swift

    var documentID: String { get }
  • The document’s owning database.

    Declaration

    Objective-C

    @property (readonly, nonatomic) CBLDatabase *_Nonnull database;

    Swift

    var database: CBLDatabase { get }
  • Is the document deleted?

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL isDeleted;

    Swift

    var isDeleted: Bool { get }
  • Checks whether the document exists in the database or not. If not, saving it will create it.

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL exists;

    Swift

    var exists: Bool { get }
  • Sequence number of the document in the database. This indicates how recently the document has been changed: every time any document is updated, the database assigns it the next sequential sequence number. Thus, if a document’s sequence property changes that means it’s been changed (on-disk); and if one document’s sequence is greater than another’s, that means it was changed more recently.

    Declaration

    Objective-C

    @property (readonly, nonatomic) uint64_t sequence;

    Swift

    var sequence: UInt64 { get }
  • The conflict resolver, if any, specific to this document. If nil, the database’s conflict resolver will be used.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) id<CBLConflictResolver>
        conflictResolver;
  • Saves property changes back to the database. If the document in the database has been updated since it was read by this CBLDocument, a conflict occurs, which will be resolved by invoking the conflict handler. This can happen if multiple application threads are writing to the database, or a pull replication is copying changes from a server.

    Declaration

    Objective-C

    - (BOOL)save:(NSError *_Nullable *_Nullable)error;

    Swift

    func save() throws
  • Deletes this document. All properties are removed, and subsequent calls to -documentWithID: will return nil. Deletion adds a special tombstone revision to the database, as bookkeeping so that the change can be replicated to other databases. Thus, it does not free up all of the disk space occupied by the document. To delete a document entirely (but without the ability to replicate this), use -purge:.

    Declaration

    Objective-C

    - (BOOL)deleteDocument:(NSError *_Nullable *_Nullable)error;

    Swift

    func delete() throws
  • Purges this document from the database. This is more drastic than deletion: it removes all traces of the document. The purge will NOT be replicated to other databases.

    Declaration

    Objective-C

    - (BOOL)purge:(NSError *_Nullable *_Nullable)error;

    Swift

    func purge() throws
  • Same as objectForKey:

    Declaration

    Objective-C

    - (nullable id)objectForKeyedSubscript:(nonnull NSString *)key;

    Swift

    subscript(key: String) -> Any? { get set }
  • Same as setObject:forKey:

    Declaration

    Objective-C

    - (void)setObject:(nullable id)value forKeyedSubscript:(nonnull NSString *)key;