DittoCollection
public class DittoCollection
A reference to a collection in a DittoStore.
-
The name of the collection.
Declaration
Swift
public var name: String { get } -
Inserts a new document into the collection and returns its assigned ID.
Throws
DittoKitError.Precondition
The document content to insert must conform toCodable.Declaration
Swift
@discardableResult public func insert<T: Codable>( _ content: T, withID id: String? = nil, isDefault: Bool = false ) throws -> StringParameters
contentThe new document to insert.
idThe ID to use for the document. If null then DittoKit 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
DittoKitError.Declaration
Swift
@discardableResult public func insert( _ content: [String: Any?], withID id: String? = nil, isDefault: Bool = false ) throws -> StringParameters
contentThe new document to insert.
idThe ID to use for the document. If null then DittoKit 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.
-
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: String) -> 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
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 DittoKit’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 how you can use the
newAttachmentfunctionality to insert an attachment into a document.if let attachment = collection.insert.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, onStatusChanged: @escaping (DittoAttachmentStatus) -> Void ) -> DittoAttachmentFetcher?Parameters
tokenThe token for the attachment that you want to fetch.
onStatusChangedA closure that will be called when the status of the request to fetch the attachment has changed. If the attachment is already available then this will be called almost immediately with a
completedstatus 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’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.
DittoCollection Class Reference