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
idThe 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
dictionaryThe 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
idThe document ID.
dictionaryThe dictionary object.
-
Set an ArrayObject object for the given key. A nil value will be converted to an NSNull.
Declaration
Swift
@discardableResult public func setArray(_ value: ArrayObject?, forKey key: String) -> SelfParameters
valueThe ArrayObject object.
keyThe key.
Return Value
The Document object.
-
Set a Blob object for the given key. A nil value will be converted to an NSNull.
Declaration
Swift
@discardableResult public func setBlob(_ value: Blob?, forKey key: String) -> SelfParameters
valueThe Blob object
keyThe key.
Return Value
The Document object.
-
Set a boolean value for the given key.
Declaration
Swift
@discardableResult public func setBoolean(_ value: Bool, forKey key: String) -> SelfParameters
valueThe boolean value.
keyThe key.
Return Value
The Document object.
-
Set a Date object for the given key. A nil value will be converted to an NSNull.
Declaration
Swift
@discardableResult public func setDate(_ value: Date?, forKey key: String) -> SelfParameters
valueThe Date object.
keyThe key.
Return Value
The Document object.
-
Set a DictionaryObject object for the given key. A nil value will be converted to an NSNull.
Declaration
Swift
@discardableResult public func setDictionary(_ value: DictionaryObject?, forKey key: String) -> SelfParameters
valueThe DictionaryObject object.
keyThe key.
Return Value
The Document object.
-
Set a double value for the given key.
Declaration
Swift
@discardableResult public func setDouble(_ value: Double, forKey key: String) -> SelfParameters
valueThe double value.
keyThe key.
Return Value
The Document object.
-
Set a float value for the given key.
Declaration
Swift
@discardableResult public func setFloat(_ value: Float, forKey key: String) -> SelfParameters
valueThe float value.
keyThe key.
Return Value
The Document object.
-
Set an int value for the given key.
Declaration
Swift
@discardableResult public func setInt(_ value: Int, forKey key: String) -> SelfParameters
valueThe integer value.
keyThe key.
Return Value
The Document object.
-
Set an int64 value for the given key.
Declaration
Swift
@discardableResult public func setInt64(_ value: Int64, forKey key: String) -> SelfParameters
valueThe int64 value.
keyThe key.
Return Value
The Document object.
-
Set a String value for the given key.
Declaration
Swift
@discardableResult public func setString(_ value: String?, forKey key: String) -> SelfParameters
valueThe String value.
keyThe Document object.
Return Value
The Document object.
-
Set a value for the given key. Allowed value types are Array, Date, Dictionary, Number types, NSNull, String, ArrayObject, Blob, DictionaryObject and nil. The Arrays and Dictionaries must contain only the above types. A nil value will be converted to an NSNull. An Date object will be converted to an ISO-8601 format string.
Declaration
Swift
@discardableResult public func setValue(_ value: Any?, forKey key: String) -> SelfParameters
valueThe value.
keyThe key.
Return Value
The Document 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>?) -> SelfParameters
dictionaryThe dictionary.
Return Value
The Document object.
-
Removes a given key and its value.
Declaration
Swift
@discardableResult public func remove(forKey key: String) -> SelfParameters
keyThe key.
Return Value
The Document object.
-
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
keyThe 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
keyThe 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) -> FragmentParameters
keyThe key.
Document Class Reference