Couchbase Lite
Objective-C API for iOS and Mac OS
CBLDocument.h
Go to the documentation of this file.
1 //
2 // CBLDocument.h
3 // CouchbaseLite
4 //
5 // Created by Jens Alfke on 6/4/12.
6 // Copyright (c) 2012-2013 Couchbase, Inc. All rights reserved.
7 //
8 
9 #import "CBLDatabase.h"
10 @class CBLSavedRevision, CBLUnsavedRevision, CBLDatabaseChange;
11 @protocol CBLDocumentModel;
12 
14 
16 @interface CBLDocument : NSObject
17 
19 @property (readonly) CBLDatabase* database;
20 
22 @property (readonly) NSString* documentID;
23 
25 @property (readonly) NSString* abbreviatedID;
26 
28 @property (readonly) BOOL isDeleted;
29 
32 @property (readonly) BOOL isGone;
33 
36 - (BOOL) deleteDocument: (NSError**)outError;
37 
40 - (BOOL) purgeDocument: (NSError**)outError;
41 
43 @property (strong, nullable) NSDate* expirationDate;
44 
45 
46 #pragma mark REVISIONS:
47 
49 @property (readonly, copy, nullable) NSString* currentRevisionID;
50 
52 @property (readonly, nullable) CBLSavedRevision* currentRevision;
53 
55 - (nullable CBLSavedRevision*) revisionWithID: (NSString*)revisionID;
56 
58 - (nullable CBLArrayOf(CBLSavedRevision*)*) getRevisionHistory: (NSError**)outError;
59 
62 - (nullable CBLArrayOf(CBLSavedRevision*)*) getConflictingRevisions: (NSError**)outError;
63 
66 - (nullable CBLArrayOf(CBLSavedRevision*)*) getLeafRevisions: (NSError**)outError;
67 
73 
74 
75 #pragma mark PROPERTIES:
76 
81 @property (readonly, copy, nullable) CBLJSONDict* properties;
82 
85 @property (readonly, copy, nullable) CBLJSONDict* userProperties;
86 
88 - (nullable id) propertyForKey: (NSString*)key;
89 
91 - (nullable id)objectForKeyedSubscript:(NSString*)key;
92 
95 - (nullable CBLSavedRevision*) putProperties: (CBLJSONDict*)properties
96  error: (NSError**)outError;
97 
109 - (nullable CBLSavedRevision*) update: (BOOL(^)(CBLUnsavedRevision*))block
110  error: (NSError**)outError;
111 
133 - (BOOL) putExistingRevisionWithProperties: (CBLJSONDict*)properties
134  attachments: (nullable NSDictionary*)attachments
135  revisionHistory: (CBLArrayOf(NSString*)*)revIDs
136  fromURL: (nullable NSURL*)sourceURL
137  error: (NSError**)outError;
138 
139 #pragma mark MODEL:
140 
144 @property (weak, nullable) id<CBLDocumentModel> modelObject;
145 
146 
147 - (instancetype) init NS_UNAVAILABLE;
148 
149 @end
150 
151 
152 
154 @protocol CBLDocumentModel <NSObject>
157 - (void) document: (CBLDocument*)doc
158  didChange: (CBLDatabaseChange*)change;
159 @end
160 
161 
162 
170 extern NSString* const kCBLDocumentChangeNotification;
171 
172 
#define NS_ASSUME_NONNULL_BEGIN
Definition: CBLBase.h:20
A CouchbaseLite database.
Definition: CBLDatabase.h:38
NSString *const kCBLDocumentChangeNotification
This notification is posted by a CBLDocument in response to a change, i.e.
#define nullable
Definition: CBLBase.h:22
CBLSavedRevision * currentRevision
The current/latest revision.
Definition: CBLDocument.h:52
A CouchbaseLite document (as opposed to any specific revision of it.)
Definition: CBLDocument.h:16
BOOL isGone
Has this document either been deleted or removed from available Sync Gateway channels? (That is, does its current revision have a &#39;_deleted&#39; or &#39;_removed&#39; property?)
Definition: CBLDocument.h:32
BOOL isDeleted
Is this document deleted? (That is, does its current revision have the &#39;_deleted&#39; property...
Definition: CBLDocument.h:28
An unsaved new revision.
Definition: CBLRevision.h:103
#define NS_ASSUME_NONNULL_END
Definition: CBLBase.h:21
NSString * abbreviatedID
An abbreviated form of the the documentID that looks like "xxxx..xxxx".
Definition: CBLDocument.h:25
NSDate * expirationDate
A date/time after which this document will be automatically purged.
Definition: CBLDocument.h:43
CBLArrayOf(NSNumber *) *CBLGeoPointToCoordPair(CBLGeoPoint pt)
Converts a point to a JSON-compatible array of two coordinates.
An existing revision of a CBLDocument.
Definition: CBLRevision.h:80
NSString * currentRevisionID
The ID of the current revision (if known; else nil).
Definition: CBLDocument.h:49
CBLDatabase * database
The document&#39;s owning database.
Definition: CBLDocument.h:19
NSString * documentID
The document&#39;s ID.
Definition: CBLDocument.h:22
CBLJSONDict * userProperties
The user-defined properties, without the ones reserved by CouchDB.
Definition: CBLDocument.h:85
id< CBLDocumentModel > modelObject
Optional reference to an application-defined model object representing this document.
Definition: CBLDocument.h:144
instancetype NS_UNAVAILABLE()
CBLUnsavedRevision * newRevision()
Creates an unsaved new revision whose parent is the currentRevision, or which will be the first revis...
CBLJSONDict * properties
The contents of the current revision of the document.
Definition: CBLDocument.h:81