Document
open class Document: Collection, ExpressibleByDictionaryLiteral
Base class for all Database documents
-
Declaration
Swift
public typealias Key = String
-
Declaration
Swift
public typealias Value = Any
-
Creates document Ids
Ids returned by this function must be unique This function is called when a new document is created without an expressly provided Id.
Declaration
Swift
public static var idFactory = {() -> String in
-
Optional
DateFormatter
used to serialize dates to/from JSON. If nil, anISO8601DateFormatter
will be used.Declaration
Swift
static public var dateFormatter: DateFormatter?
-
Metadata of this document
Declaration
Swift
public var metaData: Metadata
-
Convenience property to the metaData id property
Declaration
Swift
public var id: String
-
The document user properties expressed as a dictionary
Declaration
Swift
public internal(set) var properties: DictionaryType = [:]
-
Binary attachments associated with the Document
Declaration
Swift
public var attachments: [Attachment] = []
-
Initializes a new Document with an automatically generated unique identifier
Declaration
Swift
required public init()
-
Initializes a new Document with the provided Id and optional isLocal flag
Declaration
Swift
public init(id: String)
Parameters
id
Unique identifier of this document
-
Initializes a Document based on the provided Data, if the provided Data object contains a valid JSON dictionary.
Declaration
Swift
public convenience init?(json: Data)
Parameters
json
Data object containing serialized JSON string
-
Initializes a Document based on the provided String, if the string contains a valid JSON dictionary.
Declaration
Swift
public convenience init?(json: String)
Parameters
json
Data object containing serialized JSON string
-
Initializes a Document based on the provided
[AnyHashable: Any]
dictionary, if the dictionary can be mapped to the required[String: Any]
type.Declaration
Swift
public convenience init?(_ dictionary: [AnyHashable: Any])
Parameters
dictionary
Dictionary containing the Document information
Return Value
A Document from the provided Dictionary, or nil if any keys in the provided dictionary are not strings.
-
Initializes a Document based on the provided Dictionary and optional local flag
Declaration
Swift
public required init(_ dictionary: DictionaryType)
Parameters
dictionary
Dictionary containing the Document information
-
A type that represents the indices that are valid for subscripting the collection, in ascending order.
Declaration
Swift
public typealias Indices = DictionaryType.Indices
-
A type that provides the collection’s iteration interface and encapsulates its iteration state.
By default, a collection conforms to the Sequence protocol by supplying IndexingIterator as its associated Iterator type.
Declaration
Swift
public typealias Iterator = DictionaryType.Iterator
-
A sequence that represents a contiguous subrange of the collection’s elements.
This associated type appears as a requirement in the Sequence protocol, but it is restated here with stricter constraints. In a collection, the subsequence should also conform to Collection.
Declaration
Swift
public typealias SubSequence = DictionaryType.SubSequence
-
Declaration
Swift
public var startIndex: Index
-
Declaration
Swift
public var endIndex: DictionaryType.Index
-
Declaration
Swift
public subscript(bounds: Range<Index>) -> SubSequence
-
Declaration
Swift
public var indices: Indices
-
Accesses the value associated with the given key for reading and writing.
Declaration
Swift
public subscript(key: String) -> Value?
Parameters
key
The key to find in the dictionary.
Return Value
The value associated with
key
ifkey
is in the dictionary; otherwise,nil
. -
Declaration
Swift
public typealias Index = DictionaryType.Index
-
Helper function to use in implementing the required dictionaryLiteral initializer in subclasses
Example:
class mySubclass: Document { required init() { super.init() } required init(_ dictionary: Document.DictionaryType) { super.init(dictionary) } required convenience init(dictionaryLiteral elements: (Document.Key, Document.Value)...) { self.init(Document.dictionaryLiteral(elements: elements)) } }
Declaration
Swift
public static func dictionaryLiteral(elements: [(Key, Value)]) -> DictionaryType
-
Returns the document encoded as a JSON dictionary
Declaration
Swift
open func toJSON() -> Data?
-
Returns the current Document as the provided type subclass of a Document.
Returned object is a copy, no reference to the original Document object is retained.
Example:
let doc = Document(["id": "abc123", "foo": "bar"]) let subclass: DocumentSubclass = doc.asSubclass() print("id: \(subclass.id)" // prints "id: abc123" print("foo: \(subclass["foo"])" // prints "foo: bar"
Declaration
Swift
open func asSubclass<T: Document>() -> T
-
Metadata related to a document, but not part of the user data of the document
See moreDeclaration
Swift
public struct Metadata
-
Declaration
Swift
public var debugDescription: String
-
Declaration
Swift
public var description: String
-
Declaration
Swift
public static func == (lhs: Document, rhs: Document) -> Bool