Document

public class Document : DictionaryProtocol, Equatable, Hashable, Sequence

Couchbase Lite document. The Document is immutable.

  • id

    The document’s ID.

    Declaration

    Swift

    public var id: String { get }
  • The ID representing a document’s revision.

    Declaration

    Swift

    public var revisionID: String? { get }
  • Sequence number of the document in the database. This indicates how recently the document has been changed: every time any document is updated, the database assigns it the next sequential sequence number. Thus, if a document’s sequence property changes that means it’s been changed (on-disk); and if one document’s sequence is greater than another’s, that means it was changed more recently.

    Declaration

    Swift

    public var sequence: UInt64 { get }
  • The collection that the document belongs to.

    Declaration

    Swift

    internal(set) public var collection: Collection? { get }

Edit

  • Returns a mutable copy of the document.

    Declaration

    Swift

    public func toMutable() -> MutableDocument

    Return Value

    The MutableDocument object.

DictionaryProtocol

  • The number of properties in the document.

    Declaration

    Swift

    public var count: Int { get }
  • An array containing all keys, or an empty array if the document has no properties.

    Declaration

    Swift

    public var keys: Array<String> { get }
  • Gets a property’s value. The value types are Blob, ArrayObject, DictionaryObject, Number, or String based on the underlying data type; or nil if the value is nil or the property doesn’t exist.

    Declaration

    Swift

    public func value(forKey key: String) -> Any?

    Parameters

    key

    The key.

    Return Value

    The value or nil.

  • Gets a property’s value as a string. Returns nil if the property doesn’t exist, or its value is not a string.

    Declaration

    Swift

    public func string(forKey key: String) -> String?

    Parameters

    key

    The key.

    Return Value

    The String object or nil.

  • Get a property’s value as an NSNumber object.

    Declaration

    Swift

    public func number(forKey key: String) -> NSNumber?

    Parameters

    key

    The key.

    Return Value

    The NSNumber object.

  • Gets a property’s value as an int value. Floating point values will be rounded. The value true is returned as 1, false as 0. Returns 0 if the property doesn’t exist or does not have a numeric value.

    Declaration

    Swift

    public func int(forKey key: String) -> Int

    Parameters

    key

    The key.

    Return Value

    The Int value.

  • Gets a property’s value as an int64 value. Floating point values will be rounded. The value true is returned as 1, false as 0. Returns 0 if the property doesn’t exist or does not have a numeric value.

    Declaration

    Swift

    public func int64(forKey key: String) -> Int64

    Parameters

    key

    The key.

    Return Value

    The Int64 value.

  • Gets a property’s value as a float value. Integers will be converted to float. The value true is returned as 1.0, false as 0.0. Returns 0.0 if the property doesn’t exist or does not have a numeric value.

    Declaration

    Swift

    public func float(forKey key: String) -> Float

    Parameters

    key

    The key.

    Return Value

    The Float value.

  • Gets a property’s value as a double value. Integers will be converted to double. The value true is returned as 1.0, false as 0.0. Returns 0.0 if the property doesn’t exist or does not have a numeric value.

    Declaration

    Swift

    public func double(forKey key: String) -> Double

    Parameters

    key

    The key.

    Return Value

    The Double value.

  • Gets a property’s value as a boolean value. Returns true if the value exists, and is either true or a nonzero number.

    Declaration

    Swift

    public func boolean(forKey key: String) -> Bool

    Parameters

    key

    The key.

    Return Value

    The Bool value.

  • Get a property’s value as a Blob object. Returns nil if the property doesn’t exist, or its value is not a blob.

    Declaration

    Swift

    public func blob(forKey key: String) -> Blob?

    Parameters

    key

    The key.

    Return Value

    The Blob object or nil.

  • Gets a property’s value as a Date value. JSON does not directly support dates, so the actual property value must be a string, which is then parsed according to the ISO-8601 date format (the default used in JSON.) Returns nil if the value doesn’t exist, is not a string, or is not parseable as a date. NOTE: This is not a generic date parser! It only recognizes the ISO-8601 format, with or without milliseconds.

    Declaration

    Swift

    public func date(forKey key: String) -> Date?

    Parameters

    key

    The key.

    Return Value

    The Date value or nil

  • Get a property’s value as a 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 func array(forKey key: String) -> ArrayObject?

    Parameters

    key

    The key.

    Return Value

    The ArrayObject object or nil.

  • 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 func dictionary(forKey key: String) -> DictionaryObject?

    Parameters

    key

    The key.

    Return Value

    THe DictionaryObject object or nil.

  • Tests whether a property exists or not. This can be less expensive than value(forKey:), because it does not have to allocate an object for the property value.

    Declaration

    Swift

    public func contains(key: String) -> Bool

    Parameters

    key

    The key.

    Return Value

    True of the property exists, otherwise false.

Data

  • Gets content of the current object as a Dictionary. The value types of the values contained in the returned Dictionary object are Array, Blob, Dictionary, Number types, NSNull, and String.

    Declaration

    Swift

    public func toDictionary() -> Dictionary<String, Any>

    Return Value

    The Dictionary representing the content of the current object.

Sequence

  • Gets an iterator over the keys of the document’s properties

    Declaration

    Swift

    public func makeIterator() -> IndexingIterator<[String]>

    Return Value

    The key iterator.

Subscript

  • Subscript access to a Fragment object by key.

    Declaration

    Swift

    public subscript(key: String) -> Fragment { get }

    Parameters

    key

    The key.

Equality

  • Equal to operator for comparing two Document objects.

    Declaration

    Swift

    public static func == (doc1: Document, doc2: Document) -> Bool

Hashable

  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)

toJSON

  • Return document data as JSON String

    Declaration

    Swift

    public func toJSON() -> String