Document

public class Document : ReadOnlyDocument, DictionaryProtocol

A Couchbase Lite document.

  • Initializes a new Document object with a new random UUID. The created document will be saved into a database when you call the Database’s save() method with the document object given.

    Declaration

    Swift

    public convenience init()
  • Initializes a new Document object with the given ID. If a nil ID value is given, the document will be created with a new random UUID. The created document will be saved into a database when you call the Database’s save() method with the document object given.

    Declaration

    Swift

    public convenience init(_ id: String?)

    Parameters

    id

    the document ID.

  • Initializes a new Document object with a new random UUID and the dictionary as the content. Allowed dictionary value types are Array, Date, Dictionary, Number, NSNull, String, ArrayObject, Blob, DictionaryObject. The Arrays and Dictionaries must contain only the above types. The created document will be saved into a database when you call the Database’s save() method with the document object given.

    Declaration

    Swift

    public convenience init(dictionary: Dictionary<String, Any>?)

    Parameters

    dictionary

    the dictionary object.

  • Initializes a new Document object with a given ID and the dictionary as the content. If a nil ID value is given, the document will be created with a new random UUID. Allowed dictionary value types are Array, Date, Dictionary, Number, NSNull, String, ArrayObject, Blob, DictionaryObject. The Arrays and Dictionaries must contain only the above types. The created document will be saved into a database when you call the Database’s save() method with the document object given.

    Declaration

    Swift

    public convenience init(_ id: String?, dictionary: Dictionary<String, Any>?)

    Parameters

    id

    the document ID.

    dictionary

    the dictionary object.

  • Set a dictionary as a content. Allowed value types are Array, Date, Dictionary, Number, NSNull, String, ArrayObject, Blob, DictionaryObject. The Arrays and Dictionaries must contain only the above types. Setting the new dictionary content will replace the current data including the existing ArrayObject and DictionaryObject objects.

    Declaration

    Swift

    @discardableResult public func setDictionary(_ dictionary: Dictionary<String, Any>?) -> Self

    Parameters

    dictionary

    the dictionary.

    Return Value

    the Document object.

  • Set an object value by key. Setting the value to nil will remove the property. Allowed value types are Array, Date, Dictionary, Number, NSNull, String, ArrayObject, Blob, DictionaryObject. The Arrays and Dictionaries must contain only the above types. An Date object will be converted to an ISO-8601 format string.

    Declaration

    Swift

    @discardableResult public func set(_ value: Any?, forKey key: String) -> Self

    Parameters

    value

    the object value.

    Return Value

    the Document object.

  • Declaration

    Swift

    @discardableResult public func remove(forKey key: String) -> Self

    Parameters

    key
  • Get a property’s value as an ArrayObject, which is a mapping object of an array value. Returns nil if the property doesn’t exists, or its value is not an array.

    Declaration

    Swift

    public override func array(forKey key: String) -> ArrayObject?

    Parameters

    key

    the key.

    Return Value

    the ArrayObject object or nil if the property doesn’t exist.

  • Get a property’s value as a DictionaryObject, which is a mapping object of a dictionary value. Returns nil if the property doesn’t exists, or its value is not a dictionary.

    Declaration

    Swift

    public override func dictionary(forKey key: String) -> DictionaryObject?

    Parameters

    key

    the key.

    Return Value

    the DictionaryObject object or nil if the key doesn’t exist.

  • Equal to operator for comparing two Documents object.

    Declaration

    Swift

    public static func == (doc1: Document, doc: Document) -> Bool
  • Subscripting access to a Fragment object that represents the value of the dictionary by key.

    Declaration

    Swift

    public override subscript(key: String) -> Fragment

    Parameters

    key

    the key.

    Return Value

    the Fragment object.