CBLProperties

@protocol CBLProperties <NSObject>

CBLProperties defines a JSON-compatible object, much like an NSMutableDictionary but with type-safe accessors. It is implemented by classes CBLDocument and CBLSubdocument.

  • All of the properties contained in this object.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable)
        NSDictionary<NSString *, id> *properties;

    Swift

    var properties: [String : Any]? { get set }
  • Gets an property’s value as an object. Returns types NSNull, NSNumber, NSString, NSArray, NSDictionary, and CBLBlob, based on the underlying data type; or nil if the property doesn’t exist.

    Declaration

    Objective-C

    - (nullable id)objectForKey:(nonnull NSString *)key;

    Swift

    func object(forKey key: String) -> Any?
  • Gets a property’s value as a boolean. Returns YES if the value exists, and is either true or a nonzero number.

    Declaration

    Objective-C

    - (BOOL)booleanForKey:(nonnull NSString *)key;

    Swift

    func boolean(forKey key: String) -> Bool
  • 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

    Objective-C

    - (NSInteger)integerForKey:(nonnull NSString *)key;

    Swift

    func integer(forKey key: String) -> Int
  • 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

    Objective-C

    - (float)floatForKey:(nonnull NSString *)key;

    Swift

    func float(forKey key: String) -> Float
  • 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

    Objective-C

    - (double)doubleForKey:(nonnull NSString *)key;

    Swift

    func double(forKey key: String) -> Double
  • Gets a property’s value as a string. Returns nil if the property doesn’t exist, or its value is not a string.

    Declaration

    Objective-C

    - (nullable NSString *)stringForKey:(nonnull NSString *)key;

    Swift

    func string(forKey key: String) -> String?
  • 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

    Objective-C

    - (nullable NSDate *)dateForKey:(nonnull NSString *)key;

    Swift

    func date(forKey key: String) -> Date?
  • 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

    Objective-C

    - (nullable CBLSubdocument *)subdocumentForKey:(nonnull NSString *)key;

    Swift

    func subdocument(forKey key: String) -> CBLSubdocument?
  • Sets a property value by key. Allowed value types are NSNull, NSNumber, NSString, NSArray, NSDictionary, NSDate, CBLSubdocument, CBLBlob. NSArrays and NSDictionaries must contain only the above types. Setting a nil value will remove the property.

    Note:
    * An NSDate 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

    Objective-C

    - (void)setObject:(nullable id)value forKey:(nonnull NSString *)key;

    Swift

    func setObject(_ value: Any?, forKey key: String)
  • Sets a boolean value by key.

    Declaration

    Objective-C

    - (void)setBoolean:(BOOL)value forKey:(nonnull NSString *)key;

    Swift

    func setBoolean(_ value: Bool, forKey key: String)
  • Sets an integer value by key.

    Declaration

    Objective-C

    - (void)setInteger:(NSInteger)value forKey:(nonnull NSString *)key;

    Swift

    func setInteger(_ value: Int, forKey key: String)
  • Sets a float value by key.

    Declaration

    Objective-C

    - (void)setFloat:(float)value forKey:(nonnull NSString *)key;

    Swift

    func setFloat(_ value: Float, forKey key: String)
  • Sets a double value by key.

    Declaration

    Objective-C

    - (void)setDouble:(double)value forKey:(nonnull NSString *)key;

    Swift

    func setDouble(_ value: Double, forKey key: String)
  • Same as objectForKey:. Enables property access by subscript.

    Declaration

    Objective-C

    - (nullable id)objectForKeyedSubscript:(nonnull NSString *)key;

    Swift

    subscript(key: String) -> Any? { get set }
  • Same as setObject:forKey:. Enables setting properties by subscript.

    Declaration

    Objective-C

    - (void)setObject:(nullable id)value forKeyedSubscript:(nonnull NSString *)key;
  • Removes a property by key. This is the same as setting its value to nil.

    Declaration

    Objective-C

    - (void)removeObjectForKey:(nonnull NSString *)key;

    Swift

    func removeObject(forKey key: String)
  • 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

    Objective-C

    - (BOOL)containsObjectForKey:(nonnull NSString *)key;

    Swift

    func containsObject(forKey key: String) -> Bool
  • Reverts unsaved changes made to the properties.

    Declaration

    Objective-C

    - (void)revert;

    Swift

    func revert()