DittoDocumentID

public struct DittoDocumentID : Hashable
extension DittoDocumentID: CustomStringConvertible, CustomDebugStringConvertible
extension DittoDocumentID: ExpressibleByStringLiteral
extension DittoDocumentID: ExpressibleByBooleanLiteral
extension DittoDocumentID: ExpressibleByIntegerLiteral
extension DittoDocumentID: ExpressibleByArrayLiteral
extension DittoDocumentID: ExpressibleByDictionaryLiteral

An identifier for a DittoDocument.

Each DittoDocumentID represents a unique identifier for a document.

  • Initializes a new DittoDocumentID.

    A document ID can be created from any of the following:

    • string
    • integer
    • boolean
    • null
    • byte array
    • array (containing any of the items in this list)
    • map (where the keys must be strings and the values can be made up of any of the items in this list)

    Note that you cannot use floats or other custom types to create a document ID.

    Document IDs are also limited in size, based on their serialized representation, to 256 bytes. You will receive an error if you try to create a document ID that exceeds the size limit.

    Declaration

    Swift

    public init(value: Any?)

    Parameters

    value

    The value that represents the document identifier.

  • Used to specify a path to a key in the document ID that you can subscript further to access a nested key in the document ID.

    Declaration

    Swift

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

    Parameters

    key

    The next part of the path needed to get to the key in the document ID you wish to get the value of.

    Return Value

    The same DittoDocumentIDPath object with the provided key incorporated into the document ID path.

  • Used to specify an index in the array at the preceding key-path specified through the subscripting defined previously. You can subscript the return value further to access a further nested key in the document ID.

    Declaration

    Swift

    public subscript(index: Int) -> DittoDocumentIDPath { get }

    Parameters

    index

    The index of the array that you wish to access in the key previously specified with the preceding subscripting.

    Return Value

    The same DittoDocumentIDPath object with the provided index incorporated into the document ID path.

  • Returns a stringified representation of a document identifier.

    The returned string can be used directly in queries that you use with other Ditto functions. For example you could create a query that was like this:

    myCollection.find("_id == \(docID.toString())")
    

    Declaration

    Swift

    public func toString() -> String

    Return Value

    An String representation of the document identifier.

  • Declaration

    Swift

    public static func == (lhs: DittoDocumentID, rhs: DittoDocumentID) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)

Value accessors

  • Returns the document ID as an Any?. It will be nil if no value exists.

    Declaration

    Swift

    public var value: Any? { get }
  • Returns the document ID as a String if possible, otherwise the return value will be nil.

    Declaration

    Swift

    public var string: String? { get }
  • Returns the document ID as a String. If the key was invalid the return value will be an empty string.

    Declaration

    Swift

    public var stringValue: String { get }
  • Returns the document ID as a Bool if possible, otherwise the return value will be nil.

    Declaration

    Swift

    public var bool: Bool? { get }
  • Returns the document ID as a String. If the key was invalid the return value will be an empty string.

    Declaration

    Swift

    public var boolValue: Bool { get }
  • int

    Returns the document ID as an Int if possible, otherwise the return value will be nil.

    Declaration

    Swift

    public var int: Int? { get }
  • Returns the document ID as an Int. If the key was invalid the return value will be 0.

    Declaration

    Swift

    public var intValue: Int { get }
  • Returns the document ID as a UInt if possible, otherwise the return value will be nil.

    Declaration

    Swift

    public var uint: UInt? { get }
  • Returns the document ID as a UInt. If the key was invalid the return value will be 0.

    Declaration

    Swift

    public var uintValue: UInt { get }
  • Returns the document ID as a Float if possible, otherwise the return value will be nil.

    Declaration

    Swift

    public var float: Float? { get }
  • Returns the document ID as a Float. If the key was invalid the return value will be 0.

    Declaration

    Swift

    public var floatValue: Float { get }
  • Returns the document ID as a Double if possible, otherwise the return value will be nil.

    Declaration

    Swift

    public var double: Double? { get }
  • Returns the document ID as a Double. If the key was invalid the return value will be 0.

    Declaration

    Swift

    public var doubleValue: Double { get }
  • Returns the document ID as an Array<Any?> if possible, otherwise the return value will be nil.

    Declaration

    Swift

    public var array: [Any?]? { get }
  • Returns the document ID as an Array<Any?>. If the key was invalid the return value will be an empty array.

    Declaration

    Swift

    public var arrayValue: [Any?] { get }
  • Returns the document ID as a Dictionary<String, Any?> if possible, otherwise the return value will be nil.

    Declaration

    Swift

    public var dictionary: [String : Any?]? { get }
  • Returns the document ID as a Dictionary<String, Any?>. If the key was invalid the return value will be an empty dictionary.

    Declaration

    Swift

    public var dictionaryValue: [String : Any?] { get }

CustomStringConvertible & CustomDebugStringConvertible