Properties

public class Properties

Properties defines a JSON-compatible object, much like a Dictionory but with type-safe accessors. It is implemented by classes Document and Subdocument.

  • All of the properties contained in this object.

    Declaration

    Swift

    public var properties : [String:Any]?
  • Gets 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 subscript(key: String) -> Blob?
  • Gets a property’s value as a boolean. Returns YES if the value exists, and is either true or a nonzero number.

    Declaration

    Swift

    public subscript(key: String) -> Bool
  • Gets a property’s value as a float. 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 subscript(key: String) -> Float
  • Gets a property’s value as an NSDate. 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 subscript(key: String) -> Date?
  • Gets a property’s value as an integer. 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 subscript(key: String) -> Int
  • Gets a property’s value as a double. 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 subscript(key: String) -> Double
  • Get a property’s value as an array object. Returns nil if the property doesn’t exist, or its value is not an array.

    Declaration

    Swift

    public subscript(key: String) -> [Any]?
  • 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 subscript(key: String) -> String?
  • Gets an property’s value as an object. Returns types NSNull, Number, String, Array, Dictionary, and Blob, based on the underlying data type; or nil if the property doesn’t exist.

    Declaration

    Swift

    public subscript(key: String) -> Any?
  • Get a property’s value as a Subdocument, which is a mapping object of a Dictionary value to provide property type accessors. Returns nil if the property doesn’t exists, or its value is not a Dictionary.

    Declaration

    Swift

    public subscript(key: String) -> Subdocument?
  • Gets an property’s value as an object. Returns types NSNull, Number, String, Array, Dictionary, and Blob, based on the underlying data type; or nil if the property doesn’t exist.

    Declaration

    Swift

    public func property(_ key: String) -> Any?
  • Sets a property value by key. Allowed value types are NSNull, Number, String, Array, Dictionary, Date, Subdocument, and Blob. Arrays and Dictionaries must contain only the above types. Setting a nil value will remove the property.

    Note: * A Date object will be converted to an ISO-8601 format string. * When setting a subdocument, the subdocument will be set by reference. However, if the subdocument has already been set to another key either on the same or different document, the value of the subdocument will be copied instead.

    Declaration

    Swift

    public func setProperty(_ key: String, _ value: Any?)
  • Tests whether a property exists or not. This can be less expensive than calling property(key):, because it does not have to allocate an object for the property value.

    Declaration

    Swift

    public func contains(_ key: String) -> Bool