DictionaryObject

public class DictionaryObject : DictionaryProtocol, Equatable, Hashable, Sequence

DictionaryObject provides readonly access to dictionary data.

  • The number of entries in the dictionary.

    Declaration

    Swift

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

    Declaration

    Swift

    public var keys: Array<String> { get }
  • Gets a property’s value. The value types are Blob, ArrayObject, DictionaryObject, Number, String or NSNull based on the underlying data type; or nil if 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.

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

    Declaration

    Swift

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

    Parameters

    key

    The key.

    Return Value

    The String object or nil.

  • 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.

  • 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 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.

  • 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 -objectForKey:, because it does not have to allocate an NSObject 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.

Edit

  • Returns a mutable copy of the dictionary object.

    Declaration

    Swift

    public func toMutable() -> MutableDictionaryObject

    Return Value

    The MutableDocument object.

Sequence

  • Gets an iterator over the keys of the dictionary entries

    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 Dictionary objects.

    Declaration

    Swift

    public static func == (dict1: DictionaryObject, dict2: DictionaryObject) -> Bool

Hashable

  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)

toJSON

  • Return dictionary data as JSON String

    Declaration

    Swift

    public func toJSON() -> String