CBLDictionary
@protocol CBLDictionary <NSObject, CBLDictionaryFragment, NSFastEnumeration>
CBLDictionary protocol defines a set of methods for reading dictionary data.
-
The number of entries in the dictionary.
Declaration
Objective-C
@property (readonly, nonatomic) NSUInteger count;
Swift
var count: UInt { get }
-
An array containing all keys, or an empty array if the dictionary has no entries.
Declaration
Objective-C
@property (readonly, copy, nonatomic) NSArray<NSString *> *_Nonnull keys;
Swift
var keys: [String] { get }
-
Gets a property’s value. The object types are CBLBlob, CBLArray, CBLDictionary, NSNumber, or NSString based on the underlying data type; or nil if the property value is NSNull or the property doesn’t exist.
Declaration
Objective-C
- (nullable id)valueForKey:(nonnull NSString *)key;
Swift
func value(forKey key: String) -> Any?
Parameters
key
The key.
Return Value
The object 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
Objective-C
- (nullable NSString *)stringForKey:(nonnull NSString *)key;
Swift
func string(forKey key: String) -> String?
Parameters
key
The key.
Return Value
The NSString 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
Objective-C
- (nullable NSNumber *)numberForKey:(nonnull NSString *)key;
Swift
func number(forKey key: String) -> NSNumber?
Parameters
key
The key.
Return Value
The NSNumber object or nil.
-
Gets a property’s value as an integer 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
Objective-C
- (NSInteger)integerForKey:(nonnull NSString *)key;
Swift
func integer(forKey key: String) -> Int
Parameters
key
The key.
Return Value
The integer value.
-
Gets a property’s value as a long long 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
Objective-C
- (long long)longLongForKey:(nonnull NSString *)key;
Swift
func longLong(forKey key: String) -> Int64
Parameters
key
The key.
Return Value
The long long 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
Objective-C
- (float)floatForKey:(nonnull NSString *)key;
Swift
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
Objective-C
- (double)doubleForKey:(nonnull NSString *)key;
Swift
func double(forKey key: String) -> Double
Parameters
key
The key.
Return Value
The double value.
-
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
Parameters
key
The key.
Return Value
The boolean value.
-
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?
Parameters
key
The key.
Return Value
The NSDate object or nil.
-
Get a property’s value as a CBLBlob. Returns nil if the property doesn’t exist, or its value is not a CBLBlob.
Declaration
Objective-C
- (nullable CBLBlob *)blobForKey:(nonnull NSString *)key;
Swift
func blob(forKey key: String) -> CBLBlob?
Parameters
key
The key.
Return Value
The CBLBlob object or nil.
-
Get a property’s value as a CBLArray, 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
Objective-C
- (nullable CBLArray *)arrayForKey:(nonnull NSString *)key;
Swift
func array(forKey key: String) -> CBLArray?
Parameters
key
The key.
Return Value
The CBLArray object or nil.
-
Get a property’s value as a CBLDictionary, 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
Objective-C
- (nullable CBLDictionary *)dictionaryForKey:(nonnull NSString *)key;
Swift
func forKey(_ key: String) -> CBLDictionary?
Parameters
key
The key.
Return Value
The CBLDictionary object or nil.
-
Tests whether a property exists or not. This can be less expensive than -valuetForKey:, because it does not have to allocate an NSObject for the property value.
Declaration
Objective-C
- (BOOL)containsValueForKey:(nonnull NSString *)key;
Swift
func containsValue(forKey key: String) -> Bool
Parameters
key
The key.
Return Value
The boolean value representing whether a property exists or not.
-
Gets content of the current object as an NSDictionary. The value types of the values contained in the returned NSArray object are CBLBlob, NSArray, NSDictionary, NSNumber, NSNull, and NSString.
Declaration
Objective-C
- (nonnull NSDictionary<NSString *, id> *)toDictionary;
Swift
func toDictionary() -> [String : Any]
Return Value
The NSDictionary object representing the content of the current object.