DITCollection
@interface DITCollection : NSObject
A reference to a collection in a DITStore.
This is the entrypoint for inserting documents into a collection, as well as querying a collection.
-
The name of the collection.
Declaration
Objective-C
@property (nonatomic, readonly) NSString *_Nonnull name; -
Convenience method, same as
upsert:writeStrategy:error:whereDITWriteStrategyMergeis passed forwriteStrategy.Declaration
Objective-C
- (nullable DITDocumentID *)upsert: (nonnull NSDictionary<NSString *, id> *)content error:(NSError *_Nullable *_Nullable)error; -
Inserts a new document into the collection and returns its ID. If the document already exists, the behavior is determined by the given
writeStrategy.Declaration
Objective-C
- (nullable DITDocumentID *)upsert: (nonnull NSDictionary<NSString *, id> *)content writeStrategy:(DITWriteStrategy)writeStrategy error:(NSError *_Nullable *_Nullable)error;Parameters
contentThe new document to insert.
writeStrategySpecifies the desired strategy for inserting a document.
errorOn input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return Value
The ID of the upserted document, or
nilif upsertion failed. -
Deprecated
use
upsert(:withID:writeStrategy:error:)instead.Inserts a new document into the collection and returns its ID.
@deprecated use
upsert:writeStrategy:error:instead.Declaration
Objective-C
- (nullable DITDocumentID *)insert: (nonnull NSDictionary<NSString *, id> *)content error:(NSError *_Nullable *_Nullable)error;Parameters
contentThe new document to insert.
errorOn input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return Value
The ID of the inserted document, or
nilif insertion failed. -
Deprecated
use
upsert(:withID:writeStrategy:error:)instead.Inserts a new document into the collection and returns its ID.
@deprecated use
upsert:writeStrategy:error:instead.Declaration
Objective-C
- (nullable DITDocumentID *)insert: (nonnull NSDictionary<NSString *, id> *)content withID:(nullable DITDocumentID *)id error:(NSError *_Nullable *_Nullable)error;Parameters
contentThe new document to insert.
idThe ID to use for the document. If
NULLthen Ditto will automatically assign an ID.errorOn input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return Value
The ID of the inserted document, or
nilif insertion failed. -
Deprecated
use
upsert(:withID:writeStrategy:error:)instead.Inserts a new document into the collection and returns its ID.
@deprecated use
upsert:writeStrategy:error:instead.Declaration
Objective-C
- (nullable DITDocumentID *)insert: (nonnull NSDictionary<NSString *, id> *)content writeStrategy:(DITWriteStrategy)writeStrategy error:(NSError *_Nullable *_Nullable)error;Parameters
contentThe new document to insert.
writeStrategySpecifies the desired strategy for inserting a document.
errorOn input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return Value
The ID of the inserted document, or
nilif insertion failed. -
Deprecated
use
upsert(:withID:writeStrategy:error:)instead.Inserts a new document into the collection and returns its ID.
@deprecated use
upsert:writeStrategy:error:instead.Declaration
Objective-C
- (nullable DITDocumentID *)insert: (nonnull NSDictionary<NSString *, id> *)content withID:(nullable DITDocumentID *)id writeStrategy:(DITWriteStrategy)writeStrategy error:(NSError *_Nullable *_Nullable)error;Parameters
contentThe new document to insert.
idThe ID to use for the document. If
NULLthen Ditto will automatically assign an ID.writeStrategySpecifies the desired strategy for inserting a document.
errorOn input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return Value
The ID of the inserted document, or
nilif insertion failed. -
Deprecated
use
upsert(:writeStrategy:error:)with an equivalentDITWriteStrategyinstead.Inserts a new document into the collection and returns its ID.
@deprecated use
upsert:writeStrategy:error:instead.Declaration
Objective-C
- (nullable DITDocumentID *)insert: (nonnull NSDictionary<NSString *, id> *)content isDefault:(BOOL)isDefault error:(NSError *_Nullable *_Nullable)error;Parameters
contentThe new document to insert.
isDefaultWhether or not the data being inserted should be treated as default data or not. Set this to
trueif you want to set a default value that you expect to be overwritten by other devices in the network. The default value isfalse.errorOn input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return Value
The ID of the inserted document, or
nilif insertion failed. -
Deprecated
use
upsert(:withID:writeStrategy:error:)with an equivalentDITWriteStrategyinstead.Inserts a new document into the collection and returns its ID.
@deprecated use
upsert:writeStrategy:error:instead.Declaration
Objective-C
- (nullable DITDocumentID *)insert: (nonnull NSDictionary<NSString *, id> *)content withID:(nullable DITDocumentID *)id isDefault:(BOOL)isDefault error:(NSError *_Nullable *_Nullable)error;Parameters
contentThe new document to insert.
idThe ID to use for the document. If
NULLthen Ditto will automatically assign an ID.isDefaultWhether or not the data being inserted should be treated as default data or not. Set this to
trueif you want to set a default value that you expect to be overwritten by other devices in the network. The default value isfalse.errorOn input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return Value
The ID of the inserted document, or
nilif insertion failed. -
Generates a
DITPendingIDSpecificOperationwith the provided document ID.The returned object can be used to find and return the document or you can chain a call to
observe,observeLocal, orsubscribeif you want to get updates about the document over time. It can also be used to update, remove or evict the document.Declaration
Objective-C
- (nonnull DITPendingIDSpecificOperation *)findByID: (nonnull DITDocumentID *)docID;Parameters
docIDThe ID of the document.
Return Value
A
DITPendingIDSpecificOperationthat you can chain function calls to either get the document immediately or get updates about it over time. -
Generates a
DITPendingCursorOperationusing the provided query.The returned object can be used to find and return the documents or you can chain a call to
observe,observeLocal, orsubscribeif you want to get updates about the list of matching documents over time. It can also be used to update, remove or evict the matching documents.Declaration
Objective-C
- (nonnull DITPendingCursorOperation *)find:(nonnull NSString *)query;Parameters
queryThe query to run against the collection.
Return Value
A
DITPendingCursorOperationthat you can chain function calls to chain further query-related function calls. -
Generates a
DITPendingCursorOperationusing the provided query and query arguments.The returned object can be used to find and return the documents or you can chain a call to
observe,observeLocal, orsubscribeif you want to get updates about the list of matching documents over time. It can also be used to update, remove or evict the matching documents.This is the recommended method to use when performing queries on a collection if you have any dynamic data included in the query string. It allows you to provide a query string with placeholders, in the form of
$args.my_arg_name, along with an accompanying dictionary of arguments, in the form of{ "my_arg_name": "some value" }, and the placeholders will be appropriately replaced by the matching provided arguments from the dictionary. This includes handling things like wrapping strings in quotation marks and arrays in square brackets, for example.Declaration
Objective-C
- (nonnull DITPendingCursorOperation *) find:(nonnull NSString *)query withArgs:(nonnull NSDictionary<NSString *, id> *)queryArgs;Parameters
queryThe query to run against the collection.
queryArgsThe arguments to use to replace placeholders in the provided query.
Return Value
A
DITPendingCursorOperationthat you can chain function calls to chain further query-related function calls. -
Generates a
DITPendingCursorOperationthat relates to all documents in the collection.The returned object can be used to find and return all of the documents in the collection or you can chain a call to
observe,observeLocal, orsubscribeif you want to get updates about the documents over time. It can also be used to update, remove or evict the documents.Declaration
Objective-C
- (nonnull DITPendingCursorOperation *)findAll;Return Value
A
DITPendingCursorOperationthat you can chain function calls to chain further query-related function calls. -
Creates a new attachment, which can then be inserted into a document.
The file residing at the provided path will be copied into Ditto’s store. The
DITAttachmentobject that is returned is what you can then use to insert an attachment into a document.You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment.
Below is a snippet to show how you can use the
newAttachmentfunctionality to insert an attachment into a document.DITAttachment *attachment = [collection newAttachment:@"/path/to/my/file.pdf"]; DITDocumentID docID = [collection insert:@{@"attachment": attachment, @"other": @"string"}]; }Declaration
Objective-C
- (nullable DITAttachment *) newAttachment:(nonnull NSString *)path metadata:(nullable NSDictionary<NSString *, NSString *> *)metadata;Parameters
pathThe path to the file that you want to create an attachment with.
metadataMetadata relating to the attachment.
Return Value
A
DITAttachmentobject, which can be used to insert the attachment into a document. -
Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.
When you encounter a document that contains an attachment the attachment will not automatically be downloaded along with the document. You trigger an attachment to be downloaded locally to a device by calling this method. It will report events relating to the attachment fetch attempt as it tries to download it. The
onFetchEventblock may be called multiple times with progress events. It will then be called with either aDITAttachmentFetchEventCompletedevent or aDITAttachmentFetchEventDeletedevent. If downloading the attachment succeeds then theDITAttachmentFetchEventCompletedevent that theonFetchEventblock will be called with will hold a reference to the downloaded attachment.Declaration
Objective-C
- (nullable DITAttachmentFetcher *) fetchAttachment:(nonnull DITAttachmentToken *)token onFetchEvent: (nonnull void (^)(DITAttachmentFetchEvent *_Nonnull))onFetchEvent;Parameters
tokenThe
DITAttachmentTokenrelevant to the attachment that you wish to download and observe.onFetchEventA block that will be called when there is a update to the status of the attachment fetch attempt.
Return Value
A
DITAttachmentFetcherobject, which must be kept alive for the fetch request to proceed and for you to be notified about the attachment’s fetch status changes. If the attachment fetcher could not be created thennilwill be returned. This can happen if, for example, an invalid attachment token was provided. -
Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.
When you encounter a document that contains an attachment the attachment will not automatically be downloaded along with the document. You trigger an attachment to be downloaded locally to a device by calling this method. It will report events relating to the attachment fetch attempt as it tries to download it. The
onFetchEventblock may be called multiple times with progress events. It will then be called with either aDITAttachmentFetchEventCompletedevent or aDITAttachmentFetchEventDeletedevent. If downloading the attachment succeeds then theDITAttachmentFetchEventCompletedevent that theonFetchEventblock will be called with will hold a reference to the downloaded attachment.Declaration
Objective-C
- (nullable DITAttachmentFetcher *) fetchAttachment:(nonnull DITAttachmentToken *)token deliveryQueue:(nonnull dispatch_queue_t)dispatchQueue onFetchEvent: (nonnull void (^)(DITAttachmentFetchEvent *_Nonnull))onFetchEvent;Parameters
tokenThe
DITAttachmentTokenrelevant to the attachment that you wish to download and observe.dispatchQueueThe dispatch queue that will be used when calling the provided block to deliver fetch events. You can use the version of this method that does not take a
dispatch_queue_targument if you want the main queue to be used.onFetchEventA block that will be called when there is a update to the status of the attachment fetch attempt.
Return Value
A
DITAttachmentFetcherobject, which must be kept alive for the fetch request to proceed and for you to be notified about the attachment’s fetch status changes. If the attachment fetcher could not be created thennilwill be returned. This can happen if, for example, an invalid attachment token was provided.
DITCollection Class Reference