-
The name of the collection.
Declaration
Swift
public var name: String { get } -
Inserts a new document into the collection and returns its ID. If the document already exists, the behavior is determined by the given
writeStrategy.Throws
DittoSwiftError.Declaration
Swift
@discardableResult public func upsert( _ content: [String: Any?], writeStrategy: DittoWriteStrategy = .merge ) throws -> DittoDocumentIDParameters
contentThe new document to insert.
writeStrategySpecifies the desired strategy for inserting a document. Defaults to
.merge.Return Value
The ID of the inserted document.
-
Inserts a new document into the collection and returns its ID. If the document already exists, the behavior is determined by the given
writeStrategy.Throws
DittoSwiftError.Precondition
The document content to insert must conform toEncodable.Declaration
Swift
@discardableResult public func upsert<T: Encodable>( _ content: T, writeStrategy: DittoWriteStrategy = .merge ) throws -> DittoDocumentIDParameters
contentThe new document to insert.
writeStrategySpecifies the desired strategy for inserting a document. Defaults to
.merge.Return Value
The ID of the inserted document.
-
Inserts a new document into the collection and returns its assigned ID.
Throws
DittoSwiftError.Deprecated: use upsert() instead.
Declaration
Swift
@available(*, deprecated, message: "use `upsert(﹚` instead") @discardableResult public func insert( _ content: [String: Any?], id: Any? = nil, isDefault: Bool = false ) throws -> DittoDocumentIDParameters
contentThe new document to insert.
idThe value for the ID to use for the document. If nil then Ditto will automatically assign an ID.
isDefaultRepresents whether 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.Return Value
The ID of the inserted document.
-
Inserts a new document into the collection and returns its assigned ID.
Throws
DittoSwiftError.Deprecated: use upsert() instead.
Declaration
Swift
@available(*, deprecated, message: "use `upsert(﹚` instead") @discardableResult public func insertWithStrategy( _ content: [String: Any?], id: DittoDocumentID? = nil, writeStrategy: DittoWriteStrategy = .overwrite ) throws -> DittoDocumentIDParameters
contentThe new document to insert.
idThe ID to use for the document. If nil then Ditto will automatically assign an ID.
writeStrategySpecifies the desired strategy for inserting a document. The default value is
.overwrite.Return Value
The ID of the inserted document.
-
Inserts a new document into the collection and returns its assigned ID.
Throws
DittoSwiftError.Deprecated: use upsert() instead.
Declaration
Swift
@available(*, deprecated, message: "use `upsert(﹚` instead") @discardableResult public func insert<T: Codable>( _ content: T, id: DittoDocumentID? = nil, isDefault: Bool = false ) throws -> DittoDocumentIDParameters
contentThe new document to insert.
idThe ID to use for the document. If nil then Ditto will automatically assign an ID.
isDefaultRepresents whether 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.Return Value
The ID of the inserted document.
-
Inserts a new document into the collection and returns its assigned ID.
Throws
DittoSwiftError.Precondition
The document content to insert must conform toCodable.Deprecated: use upsert() instead.
Declaration
Swift
@available(*, deprecated, message: "use `upsert(﹚` instead") @discardableResult public func insertWithStrategy<T: Codable>( _ content: T, id: DittoDocumentID? = nil, writeStrategy: DittoWriteStrategy = .overwrite ) throws -> DittoDocumentIDParameters
contentThe new document to insert.
idThe ID to use for the document. If nil then Ditto will automatically assign an ID.
writeStrategySpecifies the desired strategy for inserting a document. The default value is
.overwrite.Return Value
The ID of the inserted document.
-
Generates a
DittoPendingIDSpecificOperationwith the provided document ID that can be used to find the document at a point in time or you can chain a call toobserve,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
Swift
public func findByID(_ id: DittoDocumentID) -> DittoPendingIDSpecificOperationParameters
idThe ID of the document.
Return Value
A
DittoPendingIDSpecificOperationthat you can chain function calls to either get the document immediately or get updates about it over time. -
Generates a
DittoPendingIDSpecificOperationwith the provided document ID that can be used to find the document at a point in time or you can chain a call toobserve,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
Swift
public func findByID(_ id: Any) -> DittoPendingIDSpecificOperationParameters
idThe ID of the document.
Return Value
A
DittoPendingIDSpecificOperationthat you can chain function calls to either get the document immediately or get updates about it over time. -
Generates a
DittoPendingCursorOperationwith the provided query that can be used to find the documents matching the query at a point in time or you can chain a call toobserve,observeLocal, orsubscribeif you want to get updates about documents matching the query as they occur. It can also be used to update, remove, or evict documents.Declaration
Swift
public func find(_ query: String) -> DittoPendingCursorOperationParameters
queryThe query to run against the collection.
Return Value
A
DittoPendingCursorOperationthat you can use to chain further query-related function calls. -
Generates a
DittoPendingCursorOperationwith the provided query and query arguments that can be used to find the documents matching the query at a point in time or you can chain a call toobserve,observeLocal, orsubscribeif you want to get updates about documents matching the query as they occur. It can also be used to update, remove, or evict documents.This is the recommended function 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
Swift
public func find(_ query: String, args queryArgs: Dictionary<String, Any?>) -> DittoPendingCursorOperationParameters
queryThe query to run against the collection.
queryArgsThe arguments to use to replace placeholders in the provided query.
Return Value
A
DittoPendingCursorOperationthat you can use to chain further query-related function calls. -
Generates a
DittoPendingCursorOperationthat can be used to find all documents in the collection at a point in time or you can chain a call toobserve,observeLocal, orsubscribeif you want to get updates about documents in the collection over time. It can also be used to update, remove or evict documents.Declaration
Swift
public func findAll() -> DittoPendingCursorOperationReturn Value
A
DittoPendingCursorOperationthat you can use 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 the 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.if let attachment = collection.newAttachment("/path/to/my/file.pdf") { let docID = try! collection.insert(["attachment": attachment, "other": "string"]) }Declaration
Swift
public func newAttachment(path: String, metadata: [String : String] = [:]) -> DittoAttachment?Parameters
pathPath to the file on disk that will be used as the attachment.
metadataOptional metadata relating to the attachment.
Return Value
A
DittoAttachmentobject, which can be used to insert the attachment into a document. -
Fetch the attachment corresponding to the provided attachment token.
Declaration
Swift
public func fetchAttachment( token: DittoAttachmentToken, deliverOn queue: DispatchQueue = .main, onFetchEvent: @escaping (DittoAttachmentFetchEvent) -> Void ) -> DittoAttachmentFetcher?Parameters
tokenThe token for the attachment that you want to fetch.
dispatchQueueThe dispatch queue that will be used to deliver live query updates. Defaults to the main queue.
onFetchEventA closure that will be called when there is an update relating to the attachment fetch attempt. If the attachment is already available then this will be called almost immediately with a
completedfetch event value.Return Value
A
DittoAttachmentFetcherobject, which must be kept alive for the fetch request to proceed and for you to be notified about the attachment fetch attempt’s events. If the attachment fetcher could not be created thennilwill be returned. This can happen if, for example, an invalid attachment token was provided. -
A Combine publisher that fetches an attachement. Can also be used to monitor progress as a large attachment is downloaded across the network.
See moreDeclaration
Swift
struct FetchAttachmentPublisher : Publisher -
A Combine publisher that fetches an attachement.
Declaration
Swift
func fetchAttachmentPublisher(attachmentToken: DittoAttachmentToken) -> FetchAttachmentPublisherParameters
attachmentTokenThe
DittoAttachmentTokenfor the attachment to fetch.Return Value
A
FetchAttachmentPublisherwhich has an output ofDittoAttachmentFetchEvent
DittoCollection Class Reference